| File | /usr/lib/perl5/vendor_perl/5.10.1/Catalyst/Plugin/I18N.pm |
| Statements Executed | 15607 |
| Statement Execution Time | 164ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 1725 | 4 | 3 | 80.7ms | 4.91s | Catalyst::Plugin::I18N::localize |
| 1735 | 5 | 3 | 69.1ms | 4.40s | Catalyst::Plugin::I18N::languages |
| 1 | 1 | 1 | 5.91ms | 6.13ms | Catalyst::Plugin::I18N::BEGIN@7 |
| 1 | 1 | 1 | 3.61ms | 4.50ms | Catalyst::Plugin::I18N::BEGIN@8 |
| 1 | 1 | 1 | 497µs | 65.9ms | Catalyst::Plugin::I18N::setup |
| 1 | 1 | 1 | 41µs | 88µs | Catalyst::Plugin::I18N::BEGIN@175 |
| 1 | 1 | 1 | 31µs | 134µs | Catalyst::Plugin::I18N::BEGIN@121 |
| 1 | 1 | 1 | 30µs | 37µs | Catalyst::Plugin::I18N::BEGIN@3 |
| 1 | 1 | 1 | 20µs | 24µs | Catalyst::Plugin::I18N::BEGIN@6 |
| 2 | 2 | 2 | 18µs | 18µs | Catalyst::Plugin::I18N::CORE:subst (opcode) |
| 1 | 1 | 1 | 17µs | 52µs | Catalyst::Plugin::I18N::BEGIN@4 |
| 0 | 0 | 0 | 0s | 0s | Catalyst::Plugin::I18N::language |
| 0 | 0 | 0 | 0s | 0s | Catalyst::Plugin::I18N::language_tag |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | package Catalyst::Plugin::I18N; | ||||
| 2 | |||||
| 3 | 3 | 45µs | 2 | 45µs | # spent 37µs (30+8) within Catalyst::Plugin::I18N::BEGIN@3 which was called
# once (30µs+8µs) by Class::MOP::__ANON__[/usr/lib/perl5/vendor_perl/5.10.1/i386-linux-thread-multi/Class/MOP.pm:103] at line 3 # spent 37µs making 1 call to Catalyst::Plugin::I18N::BEGIN@3
# spent 8µs making 1 call to strict::import |
| 4 | 3 | 44µs | 2 | 87µs | # spent 52µs (17+35) within Catalyst::Plugin::I18N::BEGIN@4 which was called
# once (17µs+35µs) by Class::MOP::__ANON__[/usr/lib/perl5/vendor_perl/5.10.1/i386-linux-thread-multi/Class/MOP.pm:103] at line 4 # spent 52µs making 1 call to Catalyst::Plugin::I18N::BEGIN@4
# spent 35µs making 1 call to warnings::import |
| 5 | |||||
| 6 | 3 | 43µs | 2 | 28µs | # spent 24µs (20+4) within Catalyst::Plugin::I18N::BEGIN@6 which was called
# once (20µs+4µs) by Class::MOP::__ANON__[/usr/lib/perl5/vendor_perl/5.10.1/i386-linux-thread-multi/Class/MOP.pm:103] at line 6 # spent 24µs making 1 call to Catalyst::Plugin::I18N::BEGIN@6
# spent 4µs making 1 call to UNIVERSAL::import |
| 7 | 3 | 302µs | 1 | 6.13ms | # spent 6.13ms (5.91+214µs) within Catalyst::Plugin::I18N::BEGIN@7 which was called
# once (5.91ms+214µs) by Class::MOP::__ANON__[/usr/lib/perl5/vendor_perl/5.10.1/i386-linux-thread-multi/Class/MOP.pm:103] at line 7 # spent 6.13ms making 1 call to Catalyst::Plugin::I18N::BEGIN@7 |
| 8 | 3 | 1.13ms | 2 | 4.51ms | # spent 4.50ms (3.61+893µs) within Catalyst::Plugin::I18N::BEGIN@8 which was called
# once (3.61ms+893µs) by Class::MOP::__ANON__[/usr/lib/perl5/vendor_perl/5.10.1/i386-linux-thread-multi/Class/MOP.pm:103] at line 8 # spent 4.50ms making 1 call to Catalyst::Plugin::I18N::BEGIN@8
# spent 8µs making 1 call to UNIVERSAL::import |
| 9 | |||||
| 10 | 1 | 306µs | require Locale::Maketext::Simple; | ||
| 11 | |||||
| 12 | 1 | 2µs | our $VERSION = '0.09'; | ||
| 13 | 1 | 7µs | our %options = ( Export => '_loc', Decode => 1 ); | ||
| 14 | |||||
| 15 | =head1 NAME | ||||
| 16 | |||||
| 17 | Catalyst::Plugin::I18N - I18N for Catalyst | ||||
| 18 | |||||
| 19 | =head1 SYNOPSIS | ||||
| 20 | |||||
| 21 | use Catalyst 'I18N'; | ||||
| 22 | |||||
| 23 | print join ' ', @{ $c->languages }; | ||||
| 24 | $c->languages( ['de'] ); | ||||
| 25 | print $c->localize('Hello Catalyst'); | ||||
| 26 | |||||
| 27 | Use a macro if you're lazy: | ||||
| 28 | |||||
| 29 | [% MACRO l(text, args) BLOCK; | ||||
| 30 | c.localize(text, args); | ||||
| 31 | END; %] | ||||
| 32 | |||||
| 33 | [% l('Hello Catalyst') %] | ||||
| 34 | [% l('Hello [_1]', 'Catalyst') %] | ||||
| 35 | [% l('lalala[_1]lalala[_2]', ['test', 'foo']) %] | ||||
| 36 | |||||
| 37 | =head1 DESCRIPTION | ||||
| 38 | |||||
| 39 | Supports mo/po files and Maketext classes under your applications I18N | ||||
| 40 | namespace. | ||||
| 41 | |||||
| 42 | # MyApp/I18N/de.po | ||||
| 43 | msgid "Hello Catalyst" | ||||
| 44 | msgstr "Hallo Katalysator" | ||||
| 45 | |||||
| 46 | #MyApp/I18N/de.pm | ||||
| 47 | package MyApp::I18N::de; | ||||
| 48 | use base 'MyApp::I18N'; | ||||
| 49 | our %Lexicon = ( 'Hello Catalyst' => 'Hallo Katalysator' ); | ||||
| 50 | 1; | ||||
| 51 | |||||
| 52 | =head2 CONFIGURATION | ||||
| 53 | |||||
| 54 | You can override any parameter sent to L<Locale::Maketext::Simple> by specifying | ||||
| 55 | a C<maketext_options> hashref to the C<Plugin::I18N> config section. For | ||||
| 56 | example, the following configuration will override the C<Decode> parameter which | ||||
| 57 | normally defaults to C<1>: | ||||
| 58 | |||||
| 59 | __PACKAGE__->config( | ||||
| 60 | 'Plugin::I18N' => | ||||
| 61 | maketext_options => { | ||||
| 62 | Decode => 0 | ||||
| 63 | } | ||||
| 64 | ); | ||||
| 65 | |||||
| 66 | =head2 EXTENDED METHODS | ||||
| 67 | |||||
| 68 | =head3 setup | ||||
| 69 | |||||
| 70 | =cut | ||||
| 71 | |||||
| 72 | # spent 65.9ms (497µs+65.4) within Catalyst::Plugin::I18N::setup which was called
# once (497µs+65.4ms) by Catalyst::Plugin::Session::setup at line 36 of mro.pm | ||||
| 73 | 11 | 250µs | my $self = shift; | ||
| 74 | $self->next::method(@_); # spent 32µs making 1 call to next::method | ||||
| 75 | my $calldir = $self; | ||||
| 76 | $calldir =~ s{::}{/}g; # spent 4µs making 1 call to Catalyst::Plugin::I18N::CORE:subst | ||||
| 77 | my $file = "$calldir.pm"; | ||||
| 78 | my $path = $INC{$file}; | ||||
| 79 | $path =~ s{\.pm$}{/I18N}; # spent 13µs making 1 call to Catalyst::Plugin::I18N::CORE:subst | ||||
| 80 | |||||
| 81 | my $user_opts = $self->config->{ 'Plugin::I18N' }->{ maketext_options } || {}; # spent 381µs making 1 call to Catalyst::config | ||||
| 82 | local %options = ( %options, Path => $path, %$user_opts ); | ||||
| 83 | |||||
| 84 | 1 | 34µs | 1 | 64.5ms | eval <<""; # spent 64.5ms making 1 call to Locale::Maketext::Simple::import |
| 85 | package $self; | ||||
| 86 | Locale::Maketext::Simple->import( \%Catalyst\::Plugin\::I18N\::options ); | ||||
| 87 | |||||
| 88 | |||||
| 89 | 1 | 204µs | if ($@) { | ||
| 90 | $self->log->error(qq/Couldn't initialize i18n "$self\::I18N", "$@"/); | ||||
| 91 | } | ||||
| 92 | else { | ||||
| 93 | $self->log->debug(qq/Initialized i18n "$self\::I18N"/) if $self->debug; # spent 305µs making 1 call to Catalyst::Log::debug
# spent 79µs making 1 call to Catalyst::_log_accessor
# spent 8µs making 1 call to Epoll::debug | ||||
| 94 | } | ||||
| 95 | } | ||||
| 96 | |||||
| 97 | =head2 METHODS | ||||
| 98 | |||||
| 99 | =head3 languages | ||||
| 100 | |||||
| 101 | Contains languages. | ||||
| 102 | |||||
| 103 | $c->languages(['de_DE']); | ||||
| 104 | print join '', @{ $c->languages }; | ||||
| 105 | |||||
| 106 | =cut | ||||
| 107 | |||||
| 108 | # spent 4.40s (69.1ms+4.34) within Catalyst::Plugin::I18N::languages which was called 1735 times, avg 2.54ms/call:
# 1725 times (68.8ms+4.31s) by Catalyst::Plugin::I18N::localize at line 174, avg 2.54ms/call
# 3 times (80µs+8.01ms) by Epoll::View::Mail::render at line 51 of Epoll/View/Mail.pm, avg 2.70ms/call
# 3 times (119µs+7.71ms) by Epoll::View::Mail::render at line 30 of Epoll/View/Mail.pm, avg 2.61ms/call
# 3 times (71µs+5.96ms) by Epoll::View::Mail::render at line 31 of Epoll/View/Mail.pm, avg 2.01ms/call
# once (35µs+2.79ms) by Epoll::Controller::Root::begin at line 37 of Epoll/Controller/Root.pm | ||||
| 109 | 6940 | 82.1ms | my ( $c, $languages ) = @_; | ||
| 110 | 1728 | 4.93ms | if ($languages) { $c->{languages} = $languages } | ||
| 111 | else { | ||||
| 112 | $c->{languages} ||= [ | ||||
| 113 | I18N::LangTags::implicate_supers( | ||||
| 114 | I18N::LangTags::Detect->http_accept_langs( | ||||
| 115 | $c->request->header('Accept-Language') | ||||
| 116 | ) | ||||
| 117 | ), | ||||
| 118 | 'i-default' | ||||
| 119 | ]; | ||||
| 120 | } | ||||
| 121 | 3 | 981µs | 2 | 237µs | # spent 134µs (31+103) within Catalyst::Plugin::I18N::BEGIN@121 which was called
# once (31µs+103µs) by Class::MOP::__ANON__[/usr/lib/perl5/vendor_perl/5.10.1/i386-linux-thread-multi/Class/MOP.pm:103] at line 121 # spent 134µs making 1 call to Catalyst::Plugin::I18N::BEGIN@121
# spent 103µs making 1 call to strict::unimport |
| 122 | &{ ref($c) . '::_loc_lang' }( @{ $c->{languages} } ); # spent 4.34s making 1735 calls to Locale::Maketext::Simple::__ANON__[Locale/Maketext/Simple.pm:197], avg 2.50ms/call | ||||
| 123 | return $c->{languages}; | ||||
| 124 | } | ||||
| 125 | |||||
| 126 | =head3 language | ||||
| 127 | |||||
| 128 | return selected locale in your locales list. | ||||
| 129 | |||||
| 130 | =cut | ||||
| 131 | |||||
| 132 | sub language { | ||||
| 133 | my $c = shift; | ||||
| 134 | my $class = ref $c || $c; | ||||
| 135 | |||||
| 136 | my $lang = ref "$class\::I18N"->get_handle( @{ $c->languages } ); | ||||
| 137 | $lang =~ s/.*:://; | ||||
| 138 | |||||
| 139 | return $lang; | ||||
| 140 | } | ||||
| 141 | |||||
| 142 | =head3 language_tag | ||||
| 143 | |||||
| 144 | return language tag for current locale. The most notable difference from this | ||||
| 145 | method in comparison to C<language()> is typically that languages and regions | ||||
| 146 | are joined with a dash and not an underscore. | ||||
| 147 | |||||
| 148 | $c->language(); # en_us | ||||
| 149 | $c->language_tag(); # en-us | ||||
| 150 | |||||
| 151 | =cut | ||||
| 152 | |||||
| 153 | sub language_tag { | ||||
| 154 | my $c = shift; | ||||
| 155 | my $class = ref $c || $c; | ||||
| 156 | |||||
| 157 | return "$class\::I18N"->get_handle( @{ $c->languages } )->language_tag; | ||||
| 158 | } | ||||
| 159 | |||||
| 160 | =head3 loc | ||||
| 161 | |||||
| 162 | =head3 localize | ||||
| 163 | |||||
| 164 | Localize text. | ||||
| 165 | |||||
| 166 | print $c->localize( 'Welcome to Catalyst, [_1]', 'sri' ); | ||||
| 167 | |||||
| 168 | =cut | ||||
| 169 | |||||
| 170 | 1 | 6µs | *loc = \&localize; | ||
| 171 | |||||
| 172 | # spent 4.91s (80.7ms+4.83) within Catalyst::Plugin::I18N::localize which was called 1725 times, avg 2.85ms/call:
# 1693 times (79.3ms+4.66s) by Template::Stash::XS::get at line 1 of Epoll/root/templates/includes/loc.tt, avg 2.80ms/call
# 27 times (1.21ms+60.0ms) by Template::Stash::XS::get at line 1 of Epoll/root/mail/includes/loc.tt, avg 2.27ms/call
# 3 times (68µs+96.3ms) by Epoll::Controller::Admin::voters at line 210 of Epoll/Controller/Admin.pm, avg 32.1ms/call
# 2 times (79µs+14.2ms) by Epoll::Controller::Admin::voters at line 228 of Epoll/Controller/Admin.pm, avg 7.13ms/call | ||||
| 173 | 6900 | 73.3ms | my $c = shift; | ||
| 174 | $c->languages; # spent 4.38s making 1725 calls to Catalyst::Plugin::I18N::languages, avg 2.54ms/call | ||||
| 175 | 3 | 290µs | 2 | 134µs | # spent 88µs (41+47) within Catalyst::Plugin::I18N::BEGIN@175 which was called
# once (41µs+47µs) by Class::MOP::__ANON__[/usr/lib/perl5/vendor_perl/5.10.1/i386-linux-thread-multi/Class/MOP.pm:103] at line 175 # spent 88µs making 1 call to Catalyst::Plugin::I18N::BEGIN@175
# spent 47µs making 1 call to strict::unimport |
| 176 | return &{ ref($c) . '::_loc' }( $_[0], @{ $_[1] } ) | ||||
| 177 | if ( ref $_[1] eq 'ARRAY' ); | ||||
| 178 | return &{ ref($c) . '::_loc' }(@_); # spent 453ms making 1725 calls to Locale::Maketext::Simple::__ANON__[Locale/Maketext/Simple.pm:167], avg 262µs/call | ||||
| 179 | } | ||||
| 180 | |||||
| 181 | =head1 SEE ALSO | ||||
| 182 | |||||
| 183 | L<Catalyst> | ||||
| 184 | |||||
| 185 | =head1 AUTHOR | ||||
| 186 | |||||
| 187 | Sebastian Riedel E<lt>sri@cpan.orgE<gt> | ||||
| 188 | |||||
| 189 | Brian Cassidy E<lt>bricas@cpan.orgE<gt> | ||||
| 190 | |||||
| 191 | Christian Hansen E<lt>chansen@cpan.orgE<gt> | ||||
| 192 | |||||
| 193 | =head1 COPYRIGHT AND LICENSE | ||||
| 194 | |||||
| 195 | This program is free software, you can redistribute it and/or modify it under | ||||
| 196 | the same terms as Perl itself. | ||||
| 197 | |||||
| 198 | =cut | ||||
| 199 | |||||
| 200 | 1 | 14µs | 1; | ||
# spent 18µs within Catalyst::Plugin::I18N::CORE:subst which was called 2 times, avg 9µs/call:
# once (13µs+0s) by Catalyst::Plugin::I18N::setup at line 79 of Catalyst/Plugin/I18N.pm
# once (4µs+0s) by Catalyst::Plugin::I18N::setup at line 76 of Catalyst/Plugin/I18N.pm |