File | /usr/local/lib/perl5/5.8.8/strict.pm |
Statements Executed | 632 |
Statement Execution Time | 8.96ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
106 | 106 | 97 | 2.85ms | 3.03ms | import | strict::
46 | 3 | 1 | 2.70ms | 2.70ms | bits | strict::
43 | 43 | 26 | 1.89ms | 4.31ms | unimport | strict::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package strict; | ||||
2 | |||||
3 | 1 | 8µs | $strict::VERSION = "1.03"; | ||
4 | |||||
5 | 1 | 18µs | my %bitmask = ( | ||
6 | refs => 0x00000002, | ||||
7 | subs => 0x00000200, | ||||
8 | vars => 0x00000400 | ||||
9 | ); | ||||
10 | |||||
11 | sub bits { | ||||
12 | 46 | 262µs | my $bits = 0; | ||
13 | 46 | 205µs | my @wrong; | ||
14 | 46 | 528µs | foreach my $s (@_) { | ||
15 | 50 | 262µs | push @wrong, $s unless exists $bitmask{$s}; | ||
16 | 50 | 613µs | $bits |= $bitmask{$s} || 0; | ||
17 | } | ||||
18 | 46 | 230µs | if (@wrong) { | ||
19 | require Carp; | ||||
20 | Carp::croak("Unknown 'strict' tag(s) '@wrong'"); | ||||
21 | } | ||||
22 | 46 | 1.01ms | $bits; | ||
23 | } | ||||
24 | |||||
25 | 1 | 36µs | 1 | 99µs | my $default_bits = bits(qw(refs subs vars)); # spent 99µs making 1 call to strict::bits |
26 | |||||
27 | # spent 3.03ms (2.85+181µs) within strict::import which was called 106 times, avg 29µs/call:
# once (101µs+66µs) by vars::BEGIN at line 8 of vars.pm
# once (45µs+66µs) by base::import at line 3 of Class/Data/Inheritable.pm
# once (60µs+49µs) by base::BEGIN at line 3 of base.pm
# once (50µs+0s) by Class::DBI::_require_class at line 3 of Class/DBI/Relationship/HasMany.pm
# once (44µs+0s) by LWP::Protocol::collect at line 133 of HTML/Entities.pm
# once (44µs+0s) by base::import at line 5 of version/vxs.pm
# once (43µs+0s) by URI::implementor at line 6 of URI/http.pm
# once (28µs+0s) by Class::DBI::_require_class at line 6 of Class/Date.pm
# once (28µs+0s) by URI::Escape::BEGIN at line 6 of URI/Escape.pm
# once (28µs+0s) by LWP::Protocol::BEGIN at line 9 of LWP/Protocol.pm
# once (28µs+0s) by base::import at line 3 of Class/DBI/AbstractSearch.pm
# once (28µs+0s) by WWW::Google::PageRank::BEGIN at line 5 of WWW/Google/PageRank.pm
# once (27µs+0s) by Class::DBI::_require_class at line 587 of Class/Date.pm
# once (27µs+0s) by base::import at line 3 of AutoLoader.pm
# once (27µs+0s) by base::import at line 3 of Class/Trigger.pm
# once (27µs+0s) by base::import at line 257 of IO/Handle.pm
# once (27µs+0s) by Net::HTTP::Methods::zlib_ok at line 6 of IO/Compress/Gzip.pm
# once (27µs+0s) by base::import at line 2 of Class/DBI/Plugin/Pager.pm
# once (27µs+0s) by DBI::_load_class at line 5 of DBIx/ContextualFetch.pm
# once (27µs+0s) by URI::BEGIN at line 3 of URI.pm
# once (27µs+0s) by base::import at line 3 of Class/DBI/Relationship.pm
# once (27µs+0s) by base::import at line 5 of Class/DBI/Plugin/RetrieveAll.pm
# once (27µs+0s) by HTTP::Headers::BEGIN at line 5 of HTTP/Headers.pm
# once (27µs+0s) by Net::HTTP::Methods::zlib_ok at line 3 of IO/Compress/Adapter/Deflate.pm
# once (27µs+0s) by Class::DBI::_require_class at line 2 of Class/Date/Const.pm
# once (27µs+0s) by HTTP::Date::BEGIN at line 11 of HTTP/Date.pm
# once (27µs+0s) by LWP::Protocol::collect at line 9 of HTML/Parser.pm
# once (26µs+0s) by HTTP::Request::BEGIN at line 9 of HTTP/Request.pm
# once (26µs+0s) by base::import at line 58 of Class/DBI/Cascade/None.pm
# once (26µs+0s) by base::import at line 1 of Class/Accessor/Chained/Fast.pm
# once (26µs+0s) by Exporter::as_heavy at line 3 of Exporter/Heavy.pm
# once (26µs+0s) by Class::DBI::_require_class at line 3 of constant.pm
# once (26µs+0s) by HTTP::Status::BEGIN at line 5 of HTTP/Status.pm
# once (26µs+0s) by LWP::Protocol::collect at line 76 of HTML/HeadParser.pm
# once (26µs+0s) by Net::HTTP::Methods::zlib_ok at line 5 of IO/Compress/Zlib/Extra.pm
# once (26µs+0s) by base::import at line 11 of List/Util.pm
# once (26µs+0s) by LWP::UserAgent::BEGIN at line 5 of LWP/UserAgent.pm
# once (26µs+0s) by Class::DBI::_require_class at line 3 of Class/DBI/SQL/Transformer.pm
# once (26µs+0s) by Net::HTTP::Methods::zlib_ok at line 3 of File/Glob.pm
# once (26µs+0s) by base::import at line 9 of Scalar/Util.pm
# once (26µs+0s) by LWP::Protocol::implementor at line 7 of Net/HTTP/Methods.pm
# once (26µs+0s) by Net::HTTP::Methods::zlib_ok at line 3 of File/GlobMapper.pm
# once (26µs+0s) by base::import at line 28 of Class/DBI/Column.pm
# once (26µs+0s) by URI::implementor at line 3 of URI/_query.pm
# once (26µs+0s) by base::import at line 5 of Ima/DBI.pm
# once (26µs+0s) by Net::HTTP::Methods::zlib_ok at line 6 of IO/Compress/Base.pm
# once (26µs+0s) by base::import at line 3 of Class/DBI/Pg.pm
# once (25µs+0s) by LWP::Protocol::implementor at line 9 of IO/Socket/INET.pm
# once (25µs+0s) by Class::DBI::_require_class at line 724 of Class/Date.pm
# once (25µs+0s) by LWP::Protocol::implementor at line 6 of LWP/Protocol/http.pm
# once (25µs+0s) by base::import at line 4 of Class/DBI/Plugin/AbstractCount.pm
# once (25µs+0s) by Net::HTTP::Methods::zlib_ok at line 3 of IO/Uncompress/Adapter/Inflate.pm
# once (25µs+0s) by base::import at line 3 of Class/DBI/Query.pm
# once (25µs+0s) by Class::DBI::_require_class at line 79 of Class/DBI/Search/Basic.pm
# once (25µs+0s) by HTTP::Response::BEGIN at line 9 of HTTP/Response.pm
# once (25µs+0s) by HTTP::Message::BEGIN at line 5 of HTTP/Message.pm
# once (25µs+0s) by Class::DBI::_require_class at line 3 of Class/DBI/Relationship/HasA.pm
# once (25µs+0s) by Net::HTTP::Methods::zlib_ok at line 3 of IO/Compress/Base/Common.pm
# once (25µs+0s) by Class::DBI::_require_class at line 14 of Class/DBI/Cascade/Delete.pm
# once (25µs+0s) by Class::DBI::_require_class at line 3 of Class/DBI/Relationship/MightHave.pm
# once (25µs+0s) by base::import at line 5 of Config.pm
# once (25µs+0s) by Net::HTTP::Methods::zlib_ok at line 3 of IO/Compress/Gzip/Constants.pm
# once (25µs+0s) by base::import at line 128 of IO/File.pm
# once (25µs+0s) by IO::Socket::connect at line 9 of IO/Select.pm
# once (25µs+0s) by base::import at line 4 of Clone.pm
# once (25µs+0s) by base::import at line 1775 of DBI.pm
# once (25µs+0s) by LWP::Protocol::implementor at line 5 of Net/HTTP.pm
# once (25µs+0s) by base::import at line 3 of File/Spec/Unix.pm
# once (25µs+0s) by Net::HTTP::Methods::zlib_ok at line 4 of IO/Uncompress/Base.pm
# once (25µs+0s) by LWP::UserAgent::get at line 5 of HTTP/Request/Common.pm
# once (24µs+0s) by base::import at line 3 of Class/Accessor.pm
# once (24µs+0s) by base::import at line 9 of attributes.pm
# once (24µs+0s) by base::import at line 4 of FileHandle.pm
# once (24µs+0s) by base::import at line 4 of Class/DBI/Plugin.pm
# once (24µs+0s) by DBI::install_driver at line 250 of DBD/Pg.pm
# once (24µs+0s) by base::import at line 2 of SQL/Abstract/Limit.pm
# once (24µs+0s) by URI::implementor at line 5 of URI/_server.pm
# once (24µs+0s) by base::import at line 12 of DBI/Const/GetInfoType.pm
# once (24µs+0s) by base::import at line 3 of File/Spec.pm
# once (24µs+0s) by URI::implementor at line 6 of URI/_generic.pm
# once (24µs+0s) by base::import at line 11 of UNIVERSAL/require.pm
# once (24µs+0s) by Net::HTTP::Methods::zlib_ok at line 8 of IO/Uncompress/Gunzip.pm
# once (24µs+0s) by base::import at line 1329 of DBI.pm
# once (24µs+0s) by base::import at line 1473 of DBI.pm
# once (24µs+0s) by base::import at line 1409 of DBI.pm
# once (24µs+0s) by base::import at line 28 of Class/DBI/ColumnGrouper.pm
# once (24µs+0s) by LWP::Protocol::implementor at line 9 of IO/Socket/UNIX.pm
# once (23µs+0s) by base::import at line 5 of version.pm
# once (23µs+0s) by Net::HTTP::Methods::zlib_ok at line 497 of IO/Compress/Base/Common.pm
# once (23µs+0s) by base::import at line 12 of Class/DBI.pm
# once (23µs+0s) by Net::HTTP::Methods::zlib_ok at line 5 of IO/Compress/RawDeflate.pm
# once (23µs+0s) by DBI::install_driver at line 170 of DBD/Pg.pm
# once (23µs+0s) by DBI::install_driver at line 13 of DBD/Pg.pm
# once (23µs+0s) by Net::HTTP::Methods::zlib_ok at line 16 of Compress/Zlib.pm
# once (23µs+0s) by Net::HTTP::Methods::zlib_ok at line 4 of IO/Uncompress/RawInflate.pm
# once (23µs+0s) by base::import at line 99 of IO/Seekable.pm
# once (22µs+0s) by Net::HTTP::Methods::zlib_ok at line 11 of Compress/Raw/Zlib.pm
# once (22µs+0s) by LWP::Protocol::implementor at line 9 of Errno.pm
# once (21µs+0s) by base::import at line 145 of SQL/Abstract.pm
# once (21µs+0s) by base::import at line 3 of Class/Accessor/Fast.pm
# once (21µs+0s) by base::import at line 4 of K2/DB2.pm
# once (21µs+0s) by Class::DBI::_require_class at line 6 of Time/Local.pm
# once (21µs+0s) by base::import at line 3 of Data/Page.pm
# once (21µs+0s) by LWP::Protocol::implementor at line 14 of IO/Socket.pm
# once (21µs+0s) by base::import at line 269 of DBI.pm
# once (20µs+0s) by base::import at line 7 of IO.pm | ||||
28 | 106 | 535µs | shift; | ||
29 | 106 | 3.49ms | 3 | 181µs | $^H |= @_ ? bits(@_) : $default_bits; # spent 181µs making 3 calls to strict::bits, avg 60µs/call |
30 | } | ||||
31 | |||||
32 | # spent 4.31ms (1.89+2.42) within strict::unimport which was called 43 times, avg 100µs/call:
# once (69µs+61µs) by HTTP::Message::BEGIN at line 370 of HTTP/Message.pm
# once (61µs+61µs) by base::import at line 603 of IO/Handle.pm
# once (42µs+78µs) by base::import at line 31 of Config.pm
# once (58µs+59µs) by LWP::Protocol::implementor at line 75 of Net/HTTP/Methods.pm
# once (41µs+74µs) by base::import at line 150 of Class/Accessor.pm
# once (52µs+58µs) by base::import at line 18 of Class/Trigger.pm
# once (48µs+58µs) by LWP::UserAgent::BEGIN at line 383 of LWP/UserAgent.pm
# once (45µs+60µs) by LWP::Protocol::implementor at line 190 of Errno.pm
# once (43µs+62µs) by base::import at line 63 of Class/DBI/Relationship.pm
# once (43µs+62µs) by base::import at line 1220 of Class/DBI.pm
# once (46µs+59µs) by base::import at line 944 of Class/DBI.pm
# once (46µs+57µs) by base::import at line 128 of AutoLoader.pm
# once (47µs+56µs) by base::import at line 511 of DBI.pm
# once (44µs+58µs) by base::import at line 277 of Ima/DBI.pm
# once (48µs+54µs) by base::import at line 652 of DBI.pm
# once (46µs+56µs) by base::import at line 764 of DBI.pm
# once (44µs+58µs) by base::import at line 18 of Class/DBI/Plugin.pm
# once (39µs+62µs) by base::import at line 107 of Class/DBI/Plugin/Pager.pm
# once (47µs+54µs) by URI::BEGIN at line 114 of URI.pm
# once (42µs+59µs) by base::import at line 1030 of Class/DBI.pm
# once (43µs+57µs) by base::import at line 95 of AutoLoader.pm
# once (42µs+58µs) by Net::HTTP::Methods::zlib_ok at line 73 of Compress/Raw/Zlib.pm
# once (43µs+57µs) by base::import at line 144 of File/Spec/Unix.pm
# once (46µs+54µs) by base::import at line 371 of Class/DBI.pm
# once (44µs+55µs) by base::import at line 989 of DBI.pm
# once (43µs+56µs) by Class::DBI::_require_class at line 94 of constant.pm
# once (44µs+55µs) by LWP::Protocol::BEGIN at line 65 of LWP/Protocol.pm
# once (41µs+57µs) by base::import at line 923 of DBI.pm
# once (43µs+55µs) by base::import at line 797 of DBI.pm
# once (42µs+56µs) by base::import at line 46 of FileHandle.pm
# once (43µs+55µs) by base::import at line 67 of Class/DBI.pm
# once (41µs+56µs) by Net::HTTP::Methods::zlib_ok at line 49 of Compress/Zlib.pm
# once (40µs+56µs) by base::import at line 29 of version.pm
# once (41µs+55µs) by base::import at line 364 of Ima/DBI.pm
# once (42µs+54µs) by base::import at line 1092 of Class/DBI.pm
# once (41µs+54µs) by base::import at line 173 of AutoLoader.pm
# once (42µs+53µs) by base::import at line 65 of Class/Trigger.pm
# once (40µs+55µs) by Class::DBI::_require_class at line 17 of Class/DBI/Relationship/HasMany.pm
# once (40µs+54µs) by base::import at line 67 of Class/DBI/Plugin/RetrieveAll.pm
# once (40µs+52µs) by base::import at line 826 of DBI.pm
# once (37µs+54µs) by base::import at line 1120 of Class/DBI.pm
# once (34µs+54µs) by Exporter::as_heavy at line 4 of Exporter/Heavy.pm
# once (25µs+0s) by base::import at line 265 of DBI.pm | ||||
33 | 43 | 242µs | shift; | ||
34 | 43 | 1.50ms | 42 | 2.42ms | $^H &= ~ (@_ ? bits(@_) : $default_bits); # spent 2.42ms making 42 calls to strict::bits, avg 58µs/call |
35 | } | ||||
36 | |||||
37 | 1 | 17µs | 1; | ||
38 | __END__ | ||||
39 | |||||
40 | =head1 NAME | ||||
41 | |||||
42 | strict - Perl pragma to restrict unsafe constructs | ||||
43 | |||||
44 | =head1 SYNOPSIS | ||||
45 | |||||
46 | use strict; | ||||
47 | |||||
48 | use strict "vars"; | ||||
49 | use strict "refs"; | ||||
50 | use strict "subs"; | ||||
51 | |||||
52 | use strict; | ||||
53 | no strict "vars"; | ||||
54 | |||||
55 | =head1 DESCRIPTION | ||||
56 | |||||
57 | If no import list is supplied, all possible restrictions are assumed. | ||||
58 | (This is the safest mode to operate in, but is sometimes too strict for | ||||
59 | casual programming.) Currently, there are three possible things to be | ||||
60 | strict about: "subs", "vars", and "refs". | ||||
61 | |||||
62 | =over 6 | ||||
63 | |||||
64 | =item C<strict refs> | ||||
65 | |||||
66 | This generates a runtime error if you | ||||
67 | use symbolic references (see L<perlref>). | ||||
68 | |||||
69 | use strict 'refs'; | ||||
70 | $ref = \$foo; | ||||
71 | print $$ref; # ok | ||||
72 | $ref = "foo"; | ||||
73 | print $$ref; # runtime error; normally ok | ||||
74 | $file = "STDOUT"; | ||||
75 | print $file "Hi!"; # error; note: no comma after $file | ||||
76 | |||||
77 | There is one exception to this rule: | ||||
78 | |||||
79 | $bar = \&{'foo'}; | ||||
80 | &$bar; | ||||
81 | |||||
82 | is allowed so that C<goto &$AUTOLOAD> would not break under stricture. | ||||
83 | |||||
84 | |||||
85 | =item C<strict vars> | ||||
86 | |||||
87 | This generates a compile-time error if you access a variable that wasn't | ||||
88 | declared via C<our> or C<use vars>, | ||||
89 | localized via C<my()>, or wasn't fully qualified. Because this is to avoid | ||||
90 | variable suicide problems and subtle dynamic scoping issues, a merely | ||||
91 | local() variable isn't good enough. See L<perlfunc/my> and | ||||
92 | L<perlfunc/local>. | ||||
93 | |||||
94 | use strict 'vars'; | ||||
95 | $X::foo = 1; # ok, fully qualified | ||||
96 | my $foo = 10; # ok, my() var | ||||
97 | local $foo = 9; # blows up | ||||
98 | |||||
99 | package Cinna; | ||||
100 | our $bar; # Declares $bar in current package | ||||
101 | $bar = 'HgS'; # ok, global declared via pragma | ||||
102 | |||||
103 | The local() generated a compile-time error because you just touched a global | ||||
104 | name without fully qualifying it. | ||||
105 | |||||
106 | Because of their special use by sort(), the variables $a and $b are | ||||
107 | exempted from this check. | ||||
108 | |||||
109 | =item C<strict subs> | ||||
110 | |||||
111 | This disables the poetry optimization, generating a compile-time error if | ||||
112 | you try to use a bareword identifier that's not a subroutine, unless it | ||||
113 | is a simple identifier (no colons) and that it appears in curly braces or | ||||
114 | on the left hand side of the C<< => >> symbol. | ||||
115 | |||||
116 | use strict 'subs'; | ||||
117 | $SIG{PIPE} = Plumber; # blows up | ||||
118 | $SIG{PIPE} = "Plumber"; # just fine: quoted string is always ok | ||||
119 | $SIG{PIPE} = \&Plumber; # preferred form | ||||
120 | |||||
121 | =back | ||||
122 | |||||
123 | See L<perlmodlib/Pragmatic Modules>. | ||||
124 | |||||
125 | =head1 HISTORY | ||||
126 | |||||
127 | C<strict 'subs'>, with Perl 5.6.1, erroneously permitted to use an unquoted | ||||
128 | compound identifier (e.g. C<Foo::Bar>) as a hash key (before C<< => >> or | ||||
129 | inside curlies), but without forcing it always to a literal string. | ||||
130 | |||||
131 | Starting with Perl 5.8.1 strict is strict about its restrictions: | ||||
132 | if unknown restrictions are used, the strict pragma will abort with | ||||
133 | |||||
134 | Unknown 'strict' tag(s) '...' | ||||
135 | |||||
136 | =cut |