Skip to content

Commit 91ded42

Browse files
committed
new instance method to reuse across process in mod_perl
1 parent 9a6137c commit 91ded42

2 files changed

Lines changed: 34 additions & 3 deletions

File tree

CHANGES

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
Revision history for Perl module Geo::Address::Formatter.
22

3-
1.9991
3+
1.9991 2026-02-15
4+
- new instance method for creating singleton and reusing across requests under mod_perl
45

56
1.9990 2026-02-11
67
- speed optimizations

lib/Geo/Address/Formatter.pm

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ Together we can address the world!
7474
7575
my $GAF = Geo::Address::Formatter->new( conf_path => '/path/to/templates' );
7676
77-
Returns one instance. The I<conf_path> is required.
77+
Returns new object. The I<conf_path> is required.
7878
7979
Optional parameters are:
8080
@@ -98,6 +98,35 @@ option to L</format_address>.
9898
9999
=cut
100100

101+
102+
=head2 instance
103+
104+
my $GAF = Geo::Address::Formatter->instance( conf_path => '/path/to/templates' );
105+
106+
Returns new instance (potentially re-used) The I<conf_path> is required.
107+
108+
Optional parameters are as in the B<new> method.
109+
110+
=cut
111+
112+
my $instance;
113+
114+
sub instance {
115+
my ($class, %params) = @_;
116+
117+
unless ($instance) {
118+
$instance = $class->new(@_);
119+
}
120+
121+
say STDERR "************* in Geo::Address::Formatter::instance ***" if ($debug);
122+
123+
# clear these fields that change on each run
124+
$instance->{final_components} = undef;
125+
$instance->{set_district_alias} = {};
126+
127+
return $instance;
128+
}
129+
101130
sub new {
102131
my ($class, %params) = @_;
103132

@@ -117,7 +146,8 @@ sub new {
117146
bless($self, $class);
118147

119148
say STDERR "************* in Geo::Address::Formatter::new ***" if ($debug);
120-
149+
150+
# is slow because lots of conf, and pre-compiling
121151
if ($self->_read_configuration($conf_path)){
122152
return $self;
123153
}

0 commit comments

Comments
 (0)