← Index
NYTProf Performance Profile   « block view • line view • sub view »
For /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
  Run on Tue Oct 15 11:58:52 2013
Reported on Tue Oct 15 12:01:02 2013

Filename/usr/share/perl/5.10/Locale/Maketext/Simple.pm
StatementsExecuted 46 statements in 1.65ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
211173µs173µsLocale::Maketext::Simple::::load_locLocale::Maketext::Simple::load_loc
222101µs299µsLocale::Maketext::Simple::::importLocale::Maketext::Simple::import
11131µs31µsLocale::Maketext::Simple::::BEGIN@5Locale::Maketext::Simple::BEGIN@5
21125µs25µsLocale::Maketext::Simple::::default_locLocale::Maketext::Simple::default_loc
11120µs28µsLocale::Maketext::Simple::::BEGIN@4Locale::Maketext::Simple::BEGIN@4
1119µs24µsLocale::Maketext::Simple::::BEGIN@118Locale::Maketext::Simple::BEGIN@118
0000s0sLocale::Maketext::Simple::::__ANON__[:120]Locale::Maketext::Simple::__ANON__[:120]
0000s0sLocale::Maketext::Simple::::__ANON__[:167]Locale::Maketext::Simple::__ANON__[:167]
0000s0sLocale::Maketext::Simple::::__ANON__[:188]Locale::Maketext::Simple::__ANON__[:188]
0000s0sLocale::Maketext::Simple::::__ANON__[:197]Locale::Maketext::Simple::__ANON__[:197]
0000s0sLocale::Maketext::Simple::::__ANON__[:211]Locale::Maketext::Simple::__ANON__[:211]
0000s0sLocale::Maketext::Simple::::_default_gettextLocale::Maketext::Simple::_default_gettext
0000s0sLocale::Maketext::Simple::::_escapeLocale::Maketext::Simple::_escape
0000s0sLocale::Maketext::Simple::::_unescapeLocale::Maketext::Simple::_unescape
0000s0sLocale::Maketext::Simple::::auto_pathLocale::Maketext::Simple::auto_path
0000s0sLocale::Maketext::Simple::::reload_locLocale::Maketext::Simple::reload_loc
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package Locale::Maketext::Simple;
21800ns$Locale::Maketext::Simple::VERSION = '0.18';
3
4330µs236µs
# spent 28µs (20+8) within Locale::Maketext::Simple::BEGIN@4 which was called: # once (20µs+8µs) by Params::Check::BEGIN@6 at line 4
use strict;
# spent 28µs making 1 call to Locale::Maketext::Simple::BEGIN@4 # spent 8µs making 1 call to strict::import
53131µs131µs
# spent 31µs within Locale::Maketext::Simple::BEGIN@5 which was called: # once (31µs+0s) by Params::Check::BEGIN@6 at line 5
use 5.004;
# spent 31µs making 1 call to Locale::Maketext::Simple::BEGIN@5
6
7=head1 NAME
8
- -
107
# spent 299µs (101+198) within Locale::Maketext::Simple::import which was called 2 times, avg 150µs/call: # once (58µs+109µs) by Params::Check::BEGIN@6 at line 6 of Params/Check.pm # once (43µs+89µs) by Module::Load::Conditional::BEGIN@7 at line 7 of Module/Load/Conditional.pm
sub import {
1081885µs my ($class, %args) = @_;
109
110 $args{Class} ||= caller;
111 $args{Style} ||= 'maketext';
112 $args{Export} ||= 'loc';
113 $args{Subclass} ||= 'I18N';
114
1152173µs my ($loc, $loc_lang) = $class->load_loc(%args);
# spent 173µs making 2 calls to Locale::Maketext::Simple::load_loc, avg 87µs/call
116225µs $loc ||= $class->default_loc(%args);
# spent 25µs making 2 calls to Locale::Maketext::Simple::default_loc, avg 12µs/call
117
11831.19ms239µs
# spent 24µs (9+15) within Locale::Maketext::Simple::BEGIN@118 which was called: # once (9µs+15µs) by Params::Check::BEGIN@6 at line 118
no strict 'refs';
# spent 24µs making 1 call to Locale::Maketext::Simple::BEGIN@118 # spent 15µs making 1 call to strict::unimport
119 *{caller(0) . "::$args{Export}"} = $loc if $args{Export};
120 *{caller(0) . "::$args{Export}_lang"} = $loc_lang || sub { 1 };
121}
122
1231400nsmy %Loc;
124
125sub reload_loc { %Loc = () }
126
127
# spent 173µs within Locale::Maketext::Simple::load_loc which was called 2 times, avg 87µs/call: # 2 times (173µs+0s) by Locale::Maketext::Simple::import at line 115, avg 87µs/call
sub load_loc {
12810183µs my ($class, %args) = @_;
129
130 my $pkg = join('::', grep { defined and length } $args{Class}, $args{Subclass});
131 return $Loc{$pkg} if exists $Loc{$pkg};
132
133 eval { require Locale::Maketext::Lexicon; 1 } or return;
134 $Locale::Maketext::Lexicon::VERSION > 0.20 or return;
135 eval { require File::Spec; 1 } or return;
136
137 my $path = $args{Path} || $class->auto_path($args{Class}) or return;
138 my $pattern = File::Spec->catfile($path, '*.[pm]o');
139 my $decode = $args{Decode} || 0;
140 my $encoding = $args{Encoding} || undef;
141
142 $decode = 1 if $encoding;
143
144 $pattern =~ s{\\}{/}g; # to counter win32 paths
145
146 eval "
147 package $pkg;
148 use base 'Locale::Maketext';
149 %${pkg}::Lexicon = ( '_AUTO' => 1 );
150 Locale::Maketext::Lexicon->import({
151 'i-default' => [ 'Auto' ],
152 '*' => [ Gettext => \$pattern ],
153 _decode => \$decode,
154 _encoding => \$encoding,
155 });
156 *tense = sub { \$_[1] . ((\$_[2] eq 'present') ? 'ing' : 'ed') }
157 unless defined &tense;
158
159 1;
160 " or die $@;
161
162 my $lh = eval { $pkg->get_handle } or return;
163 my $style = lc($args{Style});
164 if ($style eq 'maketext') {
165 $Loc{$pkg} = sub {
166 $lh->maketext(@_)
167 };
168 }
169 elsif ($style eq 'gettext') {
170 $Loc{$pkg} = sub {
171 my $str = shift;
172 $str =~ s{([\~\[\]])}{~$1}g;
173 $str =~ s{
174 ([%\\]%) # 1 - escaped sequence
175 |
176 % (?:
177 ([A-Za-z#*]\w*) # 2 - function call
178 \(([^\)]*)\) # 3 - arguments
179 |
180 ([1-9]\d*|\*) # 4 - variable
181 )
182 }{
183 $1 ? $1
184 : $2 ? "\[$2,"._unescape($3)."]"
185 : "[_$4]"
186 }egx;
187 return $lh->maketext($str, @_);
188 };
189 }
190 else {
191 die "Unknown Style: $style";
192 }
193
194 return $Loc{$pkg}, sub {
195 $lh = $pkg->get_handle(@_);
196 $lh = $pkg->get_handle(@_);
197 };
198}
199
200
# spent 25µs within Locale::Maketext::Simple::default_loc which was called 2 times, avg 12µs/call: # 2 times (25µs+0s) by Locale::Maketext::Simple::import at line 116, avg 12µs/call
sub default_loc {
201631µs my ($self, %args) = @_;
202 my $style = lc($args{Style});
203 if ($style eq 'maketext') {
204 return sub {
205 my $str = shift;
206 $str =~ s{((?<!~)(?:~~)*)\[_([1-9]\d*|\*)\]}
207 {$1%$2}g;
208 $str =~ s{((?<!~)(?:~~)*)\[([A-Za-z#*]\w*),([^\]]+)\]}
209 {"$1%$2(" . _escape($3) . ')'}eg;
210 _default_gettext($str, @_);
211 };
212 }
213 elsif ($style eq 'gettext') {
214 return \&_default_gettext;
215 }
216 else {
217 die "Unknown Style: $style";
218 }
219}
220
221sub _default_gettext {
222 my $str = shift;
223 $str =~ s{
224 % # leading symbol
225 (?: # either one of
226 \d+ # a digit, like %1
227 | # or
228 (\w+)\( # a function call -- 1
229 (?: # either
230 %\d+ # an interpolation
231 | # or
232 ([^,]*) # some string -- 2
233 ) # end either
234 (?: # maybe followed
235 , # by a comma
236 ([^),]*) # and a param -- 3
237 )? # end maybe
238 (?: # maybe followed
239 , # by another comma
240 ([^),]*) # and a param -- 4
241 )? # end maybe
242 [^)]* # and other ignorable params
243 \) # closing function call
244 ) # closing either one of
245 }{
246 my $digit = $2 || shift;
247 $digit . (
248 $1 ? (
249 ($1 eq 'tense') ? (($3 eq 'present') ? 'ing' : 'ed') :
250 ($1 eq 'quant') ? ' ' . (($digit > 1) ? ($4 || "$3s") : $3) :
251 ''
252 ) : ''
253 );
254 }egx;
255 return $str;
256};
257
258sub _escape {
259 my $text = shift;
260 $text =~ s/\b_([1-9]\d*)/%$1/g;
261 return $text;
262}
263
264sub _unescape {
265 join(',', map {
266 /\A(\s*)%([1-9]\d*|\*)(\s*)\z/ ? "$1_$2$3" : $_
267 } split(/,/, $_[0]));
268}
269
270sub auto_path {
271 my ($self, $calldir) = @_;
272 $calldir =~ s#::#/#g;
273 my $path = $INC{$calldir . '.pm'} or return;
274
275 # Try absolute path name.
276 if ($^O eq 'MacOS') {
277 (my $malldir = $calldir) =~ tr#/#:#;
278 $path =~ s#^(.*)$malldir\.pm\z#$1auto:$malldir:#s;
279 } else {
280 $path =~ s#^(.*)$calldir\.pm\z#$1auto/$calldir/#;
281 }
282
283 return $path if -d $path;
284
285 # If that failed, try relative path with normal @INC searching.
286 $path = "auto/$calldir/";
287 foreach my $inc (@INC) {
288 return "$inc/$path" if -d "$inc/$path";
289 }
290
291 return;
292}
293
29415µs1;
295
296=head1 ACKNOWLEDGMENTS
297
- -