← Index
NYTProf Performance Profile   « block view • line view • sub view »
For reply.pl
  Run on Thu Oct 21 22:40:13 2010
Reported on Thu Oct 21 22:44:39 2010

Filename/home/hinrik/perl5/perlbrew/perls/perl-5.13.5/lib/5.13.5/feature.pm
StatementsExecuted 292 statements in 915µs
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
111111725µs844µsfeature::::importfeature::import
111177µs77µsfeature::::CORE:substfeature::CORE:subst (opcode)
221142µs42µsfeature::::CORE:substcontfeature::CORE:substcont (opcode)
0000s0sfeature::::croakfeature::croak
0000s0sfeature::::unimportfeature::unimport
0000s0sfeature::::unknown_featurefeature::unknown_feature
0000s0sfeature::::unknown_feature_bundlefeature::unknown_feature_bundle
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package feature;
2
312µsour $VERSION = '1.18';
4
5# (feature name) => (internal name, used in %^H)
6123µsmy %feature = (
7 switch => 'feature_switch',
8 say => "feature_say",
9 state => "feature_state",
10 unicode_strings => "feature_unicode",
11);
12
13# This gets set (for now) in $^H as well as in %^H,
14# for runtime speed of the uc/lc/ucfirst/lcfirst functions.
15# See HINT_UNI_8_BIT in perl.h.
1611µsour $hint_uni8bit = 0x00000800;
17
18# NB. the latest bundle must be loaded by the -E switch (see toke.c)
19
2019µsmy %feature_bundle = (
21 "5.10" => [qw(switch say state)],
22 "5.11" => [qw(switch say state unicode_strings)],
23 "5.12" => [qw(switch say state unicode_strings)],
24 "5.13" => [qw(switch say state unicode_strings)],
25);
26
27# special case
2812µs$feature_bundle{"5.9.5"} = $feature_bundle{"5.10"};
29
30# TODO:
31# - think about versioned features (use feature switch => 2)
32
33=head1 NAME
34
35feature - Perl pragma to enable new features
36
37=head1 SYNOPSIS
38
39 use feature qw(switch say);
40 given ($foo) {
41 when (1) { say "\$foo == 1" }
42 when ([2,3]) { say "\$foo == 2 || \$foo == 3" }
43 when (/^a[bc]d$/) { say "\$foo eq 'abd' || \$foo eq 'acd'" }
44 when ($_ > 100) { say "\$foo > 100" }
45 default { say "None of the above" }
46 }
47
48 use feature ':5.10'; # loads all features available in perl 5.10
49
50=head1 DESCRIPTION
51
52It is usually impossible to add new syntax to Perl without breaking
53some existing programs. This pragma provides a way to minimize that
54risk. New syntactic constructs, or new semantic meanings to older
55constructs, can be enabled by C<use feature 'foo'>, and will be parsed
56only when the appropriate feature pragma is in scope.
57
58=head2 Lexical effect
59
60Like other pragmas (C<use strict>, for example), features have a lexical
61effect. C<use feature qw(foo)> will only make the feature "foo" available
62from that point to the end of the enclosing block.
63
64 {
65 use feature 'say';
66 say "say is available here";
67 }
68 print "But not here.\n";
69
70=head2 C<no feature>
71
72Features can also be turned off by using C<no feature "foo">. This too
73has lexical effect.
74
75 use feature 'say';
76 say "say is available here";
77 {
78 no feature 'say';
79 print "But not here.\n";
80 }
81 say "Yet it is here.";
82
83C<no feature> with no features specified will turn off all features.
84
85=head2 The 'switch' feature
86
87C<use feature 'switch'> tells the compiler to enable the Perl 6
88given/when construct.
89
90See L<perlsyn/"Switch statements"> for details.
91
92=head2 The 'say' feature
93
94C<use feature 'say'> tells the compiler to enable the Perl 6
95C<say> function.
96
97See L<perlfunc/say> for details.
98
99=head2 the 'state' feature
100
101C<use feature 'state'> tells the compiler to enable C<state>
102variables.
103
104See L<perlsub/"Persistent Private Variables"> for details.
105
106=head2 the 'unicode_strings' feature
107
108C<use feature 'unicode_strings'> tells the compiler to treat
109all strings outside of C<use locale> and C<use bytes> as Unicode. It is
110available starting with Perl 5.11.3, but is not fully implemented.
111
112See L<perlunicode/The "Unicode Bug"> for details.
113
114=head1 FEATURE BUNDLES
115
116It's possible to load a whole slew of features in one go, using
117a I<feature bundle>. The name of a feature bundle is prefixed with
118a colon, to distinguish it from an actual feature. At present, the
119only feature bundle is C<use feature ":5.10"> which is equivalent
120to C<use feature qw(switch say state)>.
121
122Specifying sub-versions such as the C<0> in C<5.10.0> in feature bundles has
123no effect: feature bundles are guaranteed to be the same for all sub-versions.
124
125=head1 IMPLICIT LOADING
126
127There are two ways to load the C<feature> pragma implicitly :
128
129=over 4
130
131=item *
132
133By using the C<-E> switch on the command-line instead of C<-e>. It enables
134all available features in the main compilation unit (that is, the one-liner.)
135
136=item *
137
138By requiring explicitly a minimal Perl version number for your program, with
139the C<use VERSION> construct, and when the version is higher than or equal to
1405.10.0. That is,
141
142 use 5.10.0;
143
144will do an implicit
145
146 use feature ':5.10';
147
148and so on. Note how the trailing sub-version is automatically stripped from the
149version.
150
151But to avoid portability warnings (see L<perlfunc/use>), you may prefer:
152
153 use 5.010;
154
155with the same effect.
156
157=back
158
159=cut
160
161
# spent 844µs (725+119) within feature::import which was called 11 times, avg 77µs/call: # once (82µs+16µs) by Hailo::Engine::Default::BEGIN@9.11 at line 9 of Hailo/Engine/Default.pm # once (72µs+16µs) by Hailo::Storage::Schema::BEGIN@9.8 at line 9 of Hailo/Storage/Schema.pm # once (74µs+11µs) by Hailo::Storage::SQLite::BEGIN@9.5 at line 9 of Hailo/Storage/SQLite.pm # once (73µs+11µs) by Hailo::Role::Engine::BEGIN@9.12 at line 9 of Hailo/Role/Engine.pm # once (67µs+12µs) by main::BEGIN@5.1 at line 5 of reply.pl # once (64µs+10µs) by Hailo::Role::Tokenizer::BEGIN@9.14 at line 9 of Hailo/Role/Tokenizer.pm # once (63µs+9µs) by Hailo::Storage::BEGIN@9.6 at line 9 of Hailo/Storage.pm # once (60µs+10µs) by Hailo::Role::Storage::BEGIN@9.10 at line 9 of Hailo/Role/Storage.pm # once (61µs+8µs) by Hailo::Role::Arguments::BEGIN@9.9 at line 9 of Hailo/Role/Arguments.pm # once (58µs+9µs) by Hailo::Tokenizer::Words::BEGIN@9.13 at line 9 of Hailo/Tokenizer/Words.pm # once (52µs+7µs) by Hailo::BEGIN@9.2 at line 9 of Hailo.pm
sub import {
16233114µs my $class = shift;
163 if (@_ == 0) {
164 croak("No features specified");
165 }
166 while (@_) {
167187355µs my $name = shift(@_);
16844113µs if (substr($name, 0, 1) eq ":") {
169 my $v = substr($name, 1);
17022289µs if (!exists $feature_bundle{$v}) {
17133119µs $v =~ s/^([0-9]+)\.([0-9]+).[0-9]+$/$1.$2/;
# spent 77µs making 11 calls to feature::CORE:subst, avg 7µs/call # spent 42µs making 22 calls to feature::CORE:substcont, avg 2µs/call
172 if (!exists $feature_bundle{$v}) {
173 unknown_feature_bundle(substr($name, 1));
174 }
175 }
176 unshift @_, @{$feature_bundle{$v}};
177 next;
178 }
179 if (!exists $feature{$name}) {
180 unknown_feature($name);
181 }
182 $^H{$feature{$name}} = 1;
183 $^H |= $hint_uni8bit if $name eq 'unicode_strings';
184 }
185}
186
187sub unimport {
188 my $class = shift;
189
190 # A bare C<no feature> should disable *all* features
191 if (!@_) {
192 delete @^H{ values(%feature) };
193 $^H &= ~ $hint_uni8bit;
194 return;
195 }
196
197 while (@_) {
198 my $name = shift;
199 if (substr($name, 0, 1) eq ":") {
200 my $v = substr($name, 1);
201 if (!exists $feature_bundle{$v}) {
202 $v =~ s/^([0-9]+)\.([0-9]+).[0-9]+$/$1.$2/;
203 if (!exists $feature_bundle{$v}) {
204 unknown_feature_bundle(substr($name, 1));
205 }
206 }
207 unshift @_, @{$feature_bundle{$v}};
208 next;
209 }
210 if (!exists($feature{$name})) {
211 unknown_feature($name);
212 }
213 else {
214 delete $^H{$feature{$name}};
215 $^H &= ~ $hint_uni8bit if $name eq 'unicode_strings';
216 }
217 }
218}
219
220sub unknown_feature {
221 my $feature = shift;
222 croak(sprintf('Feature "%s" is not supported by Perl %vd',
223 $feature, $^V));
224}
225
226sub unknown_feature_bundle {
227 my $feature = shift;
228 croak(sprintf('Feature bundle "%s" is not supported by Perl %vd',
229 $feature, $^V));
230}
231
232sub croak {
233 require Carp;
234 Carp::croak(@_);
235}
236
23717µs1;
 
# spent 77µs within feature::CORE:subst which was called 11 times, avg 7µs/call: # 11 times (77µs+0s) by feature::import at line 171, avg 7µs/call
sub feature::CORE:subst; # opcode
# spent 42µs within feature::CORE:substcont which was called 22 times, avg 2µs/call: # 22 times (42µs+0s) by feature::import at line 171, avg 2µs/call
sub feature::CORE:substcont; # opcode