| Filename | /home/ss5/perl5/perlbrew/perls/tapper-perl/lib/5.16.3/SelfLoader.pm |
| Statements | Executed 25 statements in 1.04ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 1 | 1 | 1 | 1.57ms | 2.91ms | SelfLoader::BEGIN@4 |
| 1 | 1 | 1 | 84µs | 100µs | SelfLoader::BEGIN@10 |
| 1 | 1 | 1 | 12µs | 12µs | SelfLoader::BEGIN@2 |
| 1 | 1 | 1 | 8µs | 30µs | SelfLoader::BEGIN@9 |
| 1 | 1 | 1 | 7µs | 17µs | SelfLoader::BEGIN@158 |
| 1 | 1 | 1 | 7µs | 20µs | SelfLoader::BEGIN@42 |
| 1 | 1 | 1 | 7µs | 18µs | SelfLoader::BEGIN@73 |
| 1 | 1 | 1 | 7µs | 15µs | SelfLoader::BEGIN@91 |
| 1 | 1 | 1 | 6µs | 15µs | SelfLoader::BEGIN@93 |
| 1 | 1 | 1 | 6µs | 15µs | SelfLoader::BEGIN@3 |
| 1 | 1 | 1 | 5µs | 5µs | SelfLoader::CORE:qr (opcode) |
| 0 | 0 | 0 | 0s | 0s | SelfLoader::AUTOLOAD |
| 0 | 0 | 0 | 0s | 0s | SelfLoader::Version |
| 0 | 0 | 0 | 0s | 0s | SelfLoader::_add_to_cache |
| 0 | 0 | 0 | 0s | 0s | SelfLoader::_load_stubs |
| 0 | 0 | 0 | 0s | 0s | SelfLoader::_package_defined |
| 0 | 0 | 0 | 0s | 0s | SelfLoader::carp |
| 0 | 0 | 0 | 0s | 0s | SelfLoader::croak |
| 0 | 0 | 0 | 0s | 0s | SelfLoader::load_stubs |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | package SelfLoader; | ||||
| 2 | 2 | 35µs | 1 | 12µs | # spent 12µs within SelfLoader::BEGIN@2 which was called:
# once (12µs+0s) by Text::Balanced::BEGIN@9 at line 2 # spent 12µs making 1 call to SelfLoader::BEGIN@2 |
| 3 | 2 | 17µs | 2 | 25µs | # spent 15µs (6+9) within SelfLoader::BEGIN@3 which was called:
# once (6µs+9µs) by Text::Balanced::BEGIN@9 at line 3 # spent 15µs making 1 call to SelfLoader::BEGIN@3
# spent 10µs making 1 call to strict::import |
| 4 | 2 | 142µs | 2 | 2.93ms | # spent 2.91ms (1.57+1.35) within SelfLoader::BEGIN@4 which was called:
# once (1.57ms+1.35ms) by Text::Balanced::BEGIN@9 at line 4 # spent 2.91ms making 1 call to SelfLoader::BEGIN@4
# spent 14µs making 1 call to Exporter::import |
| 5 | 1 | 400ns | our $VERSION = "1.20"; | ||
| 6 | |||||
| 7 | # The following bit of eval-magic is necessary to make this work on | ||||
| 8 | # perls < 5.009005. | ||||
| 9 | 2 | 40µs | 2 | 53µs | # spent 30µs (8+22) within SelfLoader::BEGIN@9 which was called:
# once (8µs+22µs) by Text::Balanced::BEGIN@9 at line 9 # spent 30µs making 1 call to SelfLoader::BEGIN@9
# spent 22µs making 1 call to vars::import |
| 10 | # spent 100µs (84+16) within SelfLoader::BEGIN@10 which was called:
# once (84µs+16µs) by Text::Balanced::BEGIN@9 at line 41 | ||||
| 11 | 1 | 3µs | if ($] > 5.009004) { | ||
| 12 | 1 | 21µs | eval <<'NEWERPERL'; # spent 75µs executing statements in string eval # includes 11µs spent executing 1 call to 1 sub defined therein. | ||
| 13 | use 5.009005; # due to new regexp features | ||||
| 14 | # allow checking for valid ': attrlist' attachments | ||||
| 15 | # see also AutoSplit | ||||
| 16 | $AttrList = qr{ | ||||
| 17 | \s* : \s* | ||||
| 18 | (?: | ||||
| 19 | # one attribute | ||||
| 20 | (?> # no backtrack | ||||
| 21 | (?! \d) \w+ | ||||
| 22 | (?<nested> \( (?: [^()]++ | (?&nested)++ )*+ \) ) ? | ||||
| 23 | ) | ||||
| 24 | (?: \s* : \s* | \s+ (?! :) ) | ||||
| 25 | )* | ||||
| 26 | }x; | ||||
| 27 | |||||
| 28 | NEWERPERL | ||||
| 29 | } | ||||
| 30 | else { | ||||
| 31 | eval <<'OLDERPERL'; | ||||
| 32 | # allow checking for valid ': attrlist' attachments | ||||
| 33 | # (we use 'our' rather than 'my' here, due to the rather complex and buggy | ||||
| 34 | # behaviour of lexicals with qr// and (??{$lex}) ) | ||||
| 35 | our $nested; | ||||
| 36 | $nested = qr{ \( (?: (?> [^()]+ ) | (??{ $nested }) )* \) }x; | ||||
| 37 | our $one_attr = qr{ (?> (?! \d) \w+ (?:$nested)? ) (?:\s*\:\s*|\s+(?!\:)) }x; | ||||
| 38 | $AttrList = qr{ \s* : \s* (?: $one_attr )* }x; | ||||
| 39 | OLDERPERL | ||||
| 40 | } | ||||
| 41 | 1 | 17µs | 1 | 100µs | } # spent 100µs making 1 call to SelfLoader::BEGIN@10 |
| 42 | 2 | 182µs | 2 | 33µs | # spent 20µs (7+13) within SelfLoader::BEGIN@42 which was called:
# once (7µs+13µs) by Text::Balanced::BEGIN@9 at line 42 # spent 20µs making 1 call to SelfLoader::BEGIN@42
# spent 13µs making 1 call to Exporter::import |
| 43 | 1 | 4µs | our @ISA = qw(Exporter); | ||
| 44 | 1 | 400ns | our @EXPORT = qw(AUTOLOAD); | ||
| 45 | sub Version {$VERSION} | ||||
| 46 | sub DEBUG () { 0 } | ||||
| 47 | |||||
| 48 | 1 | 200ns | my %Cache; # private cache for all SelfLoader's client packages | ||
| 49 | |||||
| 50 | # in croak and carp, protect $@ from "require Carp;" RT #40216 | ||||
| 51 | |||||
| 52 | sub croak { { local $@; require Carp; } goto &Carp::croak } | ||||
| 53 | sub carp { { local $@; require Carp; } goto &Carp::carp } | ||||
| 54 | |||||
| 55 | AUTOLOAD { | ||||
| 56 | our $AUTOLOAD; | ||||
| 57 | print STDERR "SelfLoader::AUTOLOAD for $AUTOLOAD\n" if DEBUG; | ||||
| 58 | my $SL_code = $Cache{$AUTOLOAD}; | ||||
| 59 | my $save = $@; # evals in both AUTOLOAD and _load_stubs can corrupt $@ | ||||
| 60 | unless ($SL_code) { | ||||
| 61 | # Maybe this pack had stubs before __DATA__, and never initialized. | ||||
| 62 | # Or, this maybe an automatic DESTROY method call when none exists. | ||||
| 63 | $AUTOLOAD =~ m/^(.*)::/; | ||||
| 64 | SelfLoader->_load_stubs($1) unless exists $Cache{"${1}::<DATA"}; | ||||
| 65 | $SL_code = $Cache{$AUTOLOAD}; | ||||
| 66 | $SL_code = "sub $AUTOLOAD { }" | ||||
| 67 | if (!$SL_code and $AUTOLOAD =~ m/::DESTROY$/); | ||||
| 68 | croak "Undefined subroutine $AUTOLOAD" unless $SL_code; | ||||
| 69 | } | ||||
| 70 | print STDERR "SelfLoader::AUTOLOAD eval: $SL_code\n" if DEBUG; | ||||
| 71 | |||||
| 72 | { | ||||
| 73 | 2 | 101µs | 2 | 29µs | # spent 18µs (7+11) within SelfLoader::BEGIN@73 which was called:
# once (7µs+11µs) by Text::Balanced::BEGIN@9 at line 73 # spent 18µs making 1 call to SelfLoader::BEGIN@73
# spent 11µs making 1 call to strict::unimport |
| 74 | eval $SL_code; | ||||
| 75 | } | ||||
| 76 | if ($@) { | ||||
| 77 | $@ =~ s/ at .*\n//; | ||||
| 78 | croak $@; | ||||
| 79 | } | ||||
| 80 | $@ = $save; | ||||
| 81 | defined(&$AUTOLOAD) || die "SelfLoader inconsistency error"; | ||||
| 82 | delete $Cache{$AUTOLOAD}; | ||||
| 83 | goto &$AUTOLOAD | ||||
| 84 | } | ||||
| 85 | |||||
| 86 | sub load_stubs { shift->_load_stubs((caller)[0]) } | ||||
| 87 | |||||
| 88 | sub _load_stubs { | ||||
| 89 | # $endlines is used by Devel::SelfStubber to capture lines after __END__ | ||||
| 90 | my($self, $callpack, $endlines) = @_; | ||||
| 91 | 2 | 29µs | 2 | 24µs | # spent 15µs (7+9) within SelfLoader::BEGIN@91 which was called:
# once (7µs+9µs) by Text::Balanced::BEGIN@9 at line 91 # spent 15µs making 1 call to SelfLoader::BEGIN@91
# spent 9µs making 1 call to strict::unimport |
| 92 | my $fh = \*{"${callpack}::DATA"}; | ||||
| 93 | 2 | 320µs | 2 | 24µs | # spent 15µs (6+9) within SelfLoader::BEGIN@93 which was called:
# once (6µs+9µs) by Text::Balanced::BEGIN@9 at line 93 # spent 15µs making 1 call to SelfLoader::BEGIN@93
# spent 9µs making 1 call to strict::import |
| 94 | my $currpack = $callpack; | ||||
| 95 | my($line,$name,@lines, @stubs, $protoype); | ||||
| 96 | |||||
| 97 | print STDERR "SelfLoader::load_stubs($callpack)\n" if DEBUG; | ||||
| 98 | croak("$callpack doesn't contain an __DATA__ token") | ||||
| 99 | unless defined fileno($fh); | ||||
| 100 | # Protect: fork() shares the file pointer between the parent and the kid | ||||
| 101 | if(sysseek($fh, tell($fh), 0)) { | ||||
| 102 | open my $nfh, '<&', $fh or croak "reopen: $!";# dup() the fd | ||||
| 103 | close $fh or die "close: $!"; # autocloses, but be paranoid | ||||
| 104 | open $fh, '<&', $nfh or croak "reopen2: $!"; # dup() the fd "back" | ||||
| 105 | close $nfh or die "close after reopen: $!"; # autocloses, but be paranoid | ||||
| 106 | $fh->untaint; | ||||
| 107 | } | ||||
| 108 | $Cache{"${currpack}::<DATA"} = 1; # indicate package is cached | ||||
| 109 | |||||
| 110 | local($/) = "\n"; | ||||
| 111 | while(defined($line = <$fh>) and $line !~ m/^__END__/) { | ||||
| 112 | if ($line =~ m/^\s*sub\s+([\w:]+)\s*((?:\([\\\$\@\%\&\*\;]*\))?(?:$AttrList)?)/) { | ||||
| 113 | push(@stubs, $self->_add_to_cache($name, $currpack, \@lines, $protoype)); | ||||
| 114 | $protoype = $2; | ||||
| 115 | @lines = ($line); | ||||
| 116 | if (index($1,'::') == -1) { # simple sub name | ||||
| 117 | $name = "${currpack}::$1"; | ||||
| 118 | } else { # sub name with package | ||||
| 119 | $name = $1; | ||||
| 120 | $name =~ m/^(.*)::/; | ||||
| 121 | if (defined(&{"${1}::AUTOLOAD"})) { | ||||
| 122 | \&{"${1}::AUTOLOAD"} == \&SelfLoader::AUTOLOAD || | ||||
| 123 | die 'SelfLoader Error: attempt to specify Selfloading', | ||||
| 124 | " sub $name in non-selfloading module $1"; | ||||
| 125 | } else { | ||||
| 126 | $self->export($1,'AUTOLOAD'); | ||||
| 127 | } | ||||
| 128 | } | ||||
| 129 | } elsif ($line =~ m/^package\s+([\w:]+)/) { # A package declared | ||||
| 130 | push(@stubs, $self->_add_to_cache($name, $currpack, \@lines, $protoype)); | ||||
| 131 | $self->_package_defined($line); | ||||
| 132 | $name = ''; | ||||
| 133 | @lines = (); | ||||
| 134 | $currpack = $1; | ||||
| 135 | $Cache{"${currpack}::<DATA"} = 1; # indicate package is cached | ||||
| 136 | if (defined(&{"${1}::AUTOLOAD"})) { | ||||
| 137 | \&{"${1}::AUTOLOAD"} == \&SelfLoader::AUTOLOAD || | ||||
| 138 | die 'SelfLoader Error: attempt to specify Selfloading', | ||||
| 139 | " package $currpack which already has AUTOLOAD"; | ||||
| 140 | } else { | ||||
| 141 | $self->export($currpack,'AUTOLOAD'); | ||||
| 142 | } | ||||
| 143 | } else { | ||||
| 144 | push(@lines,$line); | ||||
| 145 | } | ||||
| 146 | } | ||||
| 147 | if (defined($line) && $line =~ /^__END__/) { # __END__ | ||||
| 148 | unless ($line =~ /^__END__\s*DATA/) { | ||||
| 149 | if ($endlines) { | ||||
| 150 | # Devel::SelfStubber would like us to capture the lines after | ||||
| 151 | # __END__ so it can write out the entire file | ||||
| 152 | @$endlines = <$fh>; | ||||
| 153 | } | ||||
| 154 | close($fh); | ||||
| 155 | } | ||||
| 156 | } | ||||
| 157 | push(@stubs, $self->_add_to_cache($name, $currpack, \@lines, $protoype)); | ||||
| 158 | 2 | 128µs | 2 | 27µs | # spent 17µs (7+10) within SelfLoader::BEGIN@158 which was called:
# once (7µs+10µs) by Text::Balanced::BEGIN@9 at line 158 # spent 17µs making 1 call to SelfLoader::BEGIN@158
# spent 10µs making 1 call to strict::unimport |
| 159 | eval join('', @stubs) if @stubs; | ||||
| 160 | } | ||||
| 161 | |||||
| 162 | |||||
| 163 | sub _add_to_cache { | ||||
| 164 | my($self,$fullname,$pack,$lines, $protoype) = @_; | ||||
| 165 | return () unless $fullname; | ||||
| 166 | carp("Redefining sub $fullname") | ||||
| 167 | if exists $Cache{$fullname}; | ||||
| 168 | $Cache{$fullname} = join('', "\n\#line 1 \"sub $fullname\"\npackage $pack; ", @$lines); | ||||
| 169 | #$Cache{$fullname} = join('', "package $pack; ",@$lines); | ||||
| 170 | print STDERR "SelfLoader cached $fullname: $Cache{$fullname}" if DEBUG; | ||||
| 171 | # return stub to be eval'd | ||||
| 172 | defined($protoype) ? "sub $fullname $protoype;" : "sub $fullname;" | ||||
| 173 | } | ||||
| 174 | |||||
| 175 | sub _package_defined {} | ||||
| 176 | |||||
| 177 | 1 | 3µs | 1; | ||
| 178 | __END__ | ||||
# spent 5µs within SelfLoader::CORE:qr which was called:
# once (5µs+0s) by SelfLoader::BEGIN@10 at line 4 of (eval 32)[SelfLoader.pm:12] |