| File | /usr/lib/perl5/5.10.1/Module/Pluggable/Object.pm |
| Statements Executed | 3084 |
| Statement Execution Time | 36.8ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 36 | 1 | 1 | 11.0ms | 92.8ms | Module::Pluggable::Object::search_paths |
| 36 | 1 | 1 | 10.6ms | 14.6ms | Module::Pluggable::Object::_require |
| 1 | 1 | 1 | 9.99ms | 10.5ms | Module::Pluggable::Object::BEGIN@4 |
| 95 | 2 | 1 | 4.14ms | 4.14ms | Module::Pluggable::Object::_is_legit |
| 53 | 2 | 1 | 1.86ms | 18.5ms | Module::Pluggable::Object::handle_finding_plugin |
| 250 | 13 | 2 | 1.67ms | 1.67ms | Module::Pluggable::Object::CORE:match (opcode) |
| 3 | 2 | 2 | 1.67ms | 105ms | Module::Pluggable::Object::plugins |
| 13 | 2 | 1 | 1.55ms | 14.7ms | Module::Pluggable::Object::handle_innerpackages |
| 96 | 1 | 2 | 1.01ms | 1.01ms | Module::Pluggable::Object::CORE:ftis (opcode) |
| 30 | 2 | 1 | 958µs | 1.26ms | Module::Pluggable::Object::__ANON__[:281] |
| 25 | 1 | 1 | 835µs | 986µs | Module::Pluggable::Object::_is_editor_junk |
| 1 | 1 | 1 | 784µs | 1.33ms | Module::Pluggable::Object::BEGIN@6 |
| 3 | 1 | 1 | 635µs | 93.5ms | Module::Pluggable::Object::search_directories |
| 64 | 3 | 2 | 614µs | 614µs | Module::Pluggable::Object::CORE:regcomp (opcode) |
| 9 | 1 | 2 | 533µs | 533µs | Module::Pluggable::Object::CORE:open (opcode) |
| 5 | 1 | 1 | 478µs | 6.45ms | Module::Pluggable::Object::find_files |
| 9 | 1 | 2 | 326µs | 326µs | Module::Pluggable::Object::CORE:readline (opcode) |
| 41 | 2 | 2 | 281µs | 281µs | Module::Pluggable::Object::CORE:qr (opcode) |
| 3 | 1 | 1 | 127µs | 127µs | Module::Pluggable::Object::_setup_exceptions |
| 9 | 1 | 2 | 126µs | 126µs | Module::Pluggable::Object::CORE:close (opcode) |
| 3 | 2 | 2 | 85µs | 85µs | Module::Pluggable::Object::new |
| 25 | 1 | 2 | 48µs | 48µs | Module::Pluggable::Object::CORE:subst (opcode) |
| 1 | 1 | 1 | 38µs | 98µs | Module::Pluggable::Object::BEGIN@8 |
| 1 | 1 | 1 | 30µs | 40µs | Module::Pluggable::Object::BEGIN@3 |
| 1 | 1 | 1 | 20µs | 122µs | Module::Pluggable::Object::BEGIN@5 |
| 1 | 1 | 1 | 17µs | 74µs | Module::Pluggable::Object::BEGIN@7 |
| 1 | 1 | 1 | 14µs | 50µs | Module::Pluggable::Object::BEGIN@9 |
| 5 | 1 | 2 | 10µs | 10µs | Module::Pluggable::Object::CORE:ftdir (opcode) |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | package Module::Pluggable::Object; | ||||
| 2 | |||||
| 3 | 3 | 42µs | 2 | 51µs | # spent 40µs (30+11) within Module::Pluggable::Object::BEGIN@3 which was called
# once (30µs+11µs) by Catalyst::BEGIN@19 at line 3 # spent 40µs making 1 call to Module::Pluggable::Object::BEGIN@3
# spent 10µs making 1 call to strict::import |
| 4 | 3 | 189µs | 1 | 10.5ms | # spent 10.5ms (9.99+493µs) within Module::Pluggable::Object::BEGIN@4 which was called
# once (9.99ms+493µs) by Catalyst::BEGIN@19 at line 4 # spent 10.5ms making 1 call to Module::Pluggable::Object::BEGIN@4 |
| 5 | 3 | 50µs | 2 | 224µs | # spent 122µs (20+102) within Module::Pluggable::Object::BEGIN@5 which was called
# once (20µs+102µs) by Catalyst::BEGIN@19 at line 5 # spent 122µs making 1 call to Module::Pluggable::Object::BEGIN@5
# spent 102µs making 1 call to Exporter::import |
| 6 | 3 | 309µs | 2 | 1.50ms | # spent 1.33ms (784µs+544µs) within Module::Pluggable::Object::BEGIN@6 which was called
# once (784µs+544µs) by Catalyst::BEGIN@19 at line 6 # spent 1.33ms making 1 call to Module::Pluggable::Object::BEGIN@6
# spent 168µs making 1 call to Exporter::import |
| 7 | 3 | 42µs | 2 | 130µs | # spent 74µs (17+56) within Module::Pluggable::Object::BEGIN@7 which was called
# once (17µs+56µs) by Catalyst::BEGIN@19 at line 7 # spent 74µs making 1 call to Module::Pluggable::Object::BEGIN@7
# spent 56µs making 1 call to Exporter::import |
| 8 | 3 | 49µs | 2 | 158µs | # spent 98µs (38+60) within Module::Pluggable::Object::BEGIN@8 which was called
# once (38µs+60µs) by Catalyst::BEGIN@19 at line 8 # spent 98µs making 1 call to Module::Pluggable::Object::BEGIN@8
# spent 60µs making 1 call to Exporter::import |
| 9 | 3 | 3.14ms | 2 | 85µs | # spent 50µs (14+36) within Module::Pluggable::Object::BEGIN@9 which was called
# once (14µs+36µs) by Catalyst::BEGIN@19 at line 9 # spent 50µs making 1 call to Module::Pluggable::Object::BEGIN@9
# spent 36µs making 1 call to vars::import |
| 10 | |||||
| 11 | 1 | 2µs | $VERSION = '3.9'; | ||
| 12 | |||||
| 13 | |||||
| 14 | # spent 85µs within Module::Pluggable::Object::new which was called 3 times, avg 28µs/call:
# 2 times (64µs+0s) by Config::Any::finder at line 253 of Config/Any.pm, avg 32µs/call
# once (22µs+0s) by Catalyst::locate_components at line 2455 of Catalyst.pm | ||||
| 15 | 9 | 162µs | my $class = shift; | ||
| 16 | my %opts = @_; | ||||
| 17 | |||||
| 18 | return bless \%opts, $class; | ||||
| 19 | |||||
| 20 | } | ||||
| 21 | |||||
| 22 | ### Eugggh, this code smells | ||||
| 23 | ### This is what happens when you keep adding patches | ||||
| 24 | ### *sigh* | ||||
| 25 | |||||
| 26 | |||||
| 27 | # spent 105ms (1.67+103) within Module::Pluggable::Object::plugins which was called 3 times, avg 35.0ms/call:
# 2 times (1.30ms+68.4ms) by Config::Any::plugins at line 272 of Config/Any.pm, avg 34.8ms/call
# once (373µs+34.8ms) by Catalyst::locate_components at line 2459 of Catalyst.pm | ||||
| 28 | 48 | 502µs | my $self = shift; | ||
| 29 | |||||
| 30 | # override 'require' | ||||
| 31 | $self->{'require'} = 1 if $self->{'inner'}; | ||||
| 32 | |||||
| 33 | my $filename = $self->{'filename'}; | ||||
| 34 | my $pkg = $self->{'package'}; | ||||
| 35 | |||||
| 36 | # Get the exception params instantiated | ||||
| 37 | $self->_setup_exceptions; # spent 127µs making 3 calls to Module::Pluggable::Object::_setup_exceptions, avg 42µs/call | ||||
| 38 | |||||
| 39 | # automatically turn a scalar search path or namespace into a arrayref | ||||
| 40 | for (qw(search_path search_dirs)) { | ||||
| 41 | 6 | 42µs | $self->{$_} = [ $self->{$_} ] if exists $self->{$_} && !ref($self->{$_}); | ||
| 42 | } | ||||
| 43 | |||||
| 44 | # default search path is '<Module>::<Name>::Plugin' | ||||
| 45 | $self->{'search_path'} = ["${pkg}::Plugin"] unless $self->{'search_path'}; | ||||
| 46 | |||||
| 47 | |||||
| 48 | #my %opts = %$self; | ||||
| 49 | |||||
| 50 | |||||
| 51 | # check to see if we're running under test | ||||
| 52 | my @SEARCHDIR = exists $INC{"blib.pm"} && defined $filename && $filename =~ m!(^|/)blib/! ? grep {/blib/} @INC : @INC; | ||||
| 53 | |||||
| 54 | # add any search_dir params | ||||
| 55 | unshift @SEARCHDIR, @{$self->{'search_dirs'}} if defined $self->{'search_dirs'}; | ||||
| 56 | |||||
| 57 | |||||
| 58 | my @plugins = $self->search_directories(@SEARCHDIR); # spent 93.5ms making 3 calls to Module::Pluggable::Object::search_directories, avg 31.2ms/call | ||||
| 59 | push(@plugins, $self->handle_innerpackages($_)) for @{$self->{'search_path'}}; # spent 7.53ms making 8 calls to Module::Pluggable::Object::handle_innerpackages, avg 941µs/call | ||||
| 60 | |||||
| 61 | # push @plugins, map { print STDERR "$_\n"; $_->require } list_packages($_) for (@{$self->{'search_path'}}); | ||||
| 62 | |||||
| 63 | # return blank unless we've found anything | ||||
| 64 | 1 | 64µs | return () unless @plugins; | ||
| 65 | |||||
| 66 | |||||
| 67 | |||||
| 68 | # remove duplicates | ||||
| 69 | # probably not necessary but hey ho | ||||
| 70 | my %plugins; | ||||
| 71 | for(@plugins) { | ||||
| 72 | 100 | 782µs | 53 | 2.07ms | next unless $self->_is_legit($_); # spent 2.07ms making 53 calls to Module::Pluggable::Object::_is_legit, avg 39µs/call |
| 73 | $plugins{$_} = 1; | ||||
| 74 | } | ||||
| 75 | |||||
| 76 | # are we instantiating or requring? | ||||
| 77 | 3 | 75µs | if (defined $self->{'instantiate'}) { | ||
| 78 | my $method = $self->{'instantiate'}; | ||||
| 79 | return map { ($_->can($method)) ? $_->$method(@_) : () } keys %plugins; | ||||
| 80 | } else { | ||||
| 81 | # no? just return the names | ||||
| 82 | return keys %plugins; | ||||
| 83 | } | ||||
| 84 | |||||
| 85 | |||||
| 86 | } | ||||
| 87 | |||||
| 88 | # spent 127µs within Module::Pluggable::Object::_setup_exceptions which was called 3 times, avg 42µs/call:
# 3 times (127µs+0s) by Module::Pluggable::Object::plugins at line 37, avg 42µs/call | ||||
| 89 | 33 | 118µs | my $self = shift; | ||
| 90 | |||||
| 91 | my %only; | ||||
| 92 | my %except; | ||||
| 93 | my $only; | ||||
| 94 | my $except; | ||||
| 95 | |||||
| 96 | if (defined $self->{'only'}) { | ||||
| 97 | if (ref($self->{'only'}) eq 'ARRAY') { | ||||
| 98 | %only = map { $_ => 1 } @{$self->{'only'}}; | ||||
| 99 | } elsif (ref($self->{'only'}) eq 'Regexp') { | ||||
| 100 | $only = $self->{'only'} | ||||
| 101 | } elsif (ref($self->{'only'}) eq '') { | ||||
| 102 | $only{$self->{'only'}} = 1; | ||||
| 103 | } | ||||
| 104 | } | ||||
| 105 | |||||
| 106 | |||||
| 107 | 2 | 23µs | if (defined $self->{'except'}) { | ||
| 108 | if (ref($self->{'except'}) eq 'ARRAY') { | ||||
| 109 | %except = map { $_ => 1 } @{$self->{'except'}}; | ||||
| 110 | } elsif (ref($self->{'except'}) eq 'Regexp') { | ||||
| 111 | $except = $self->{'except'} | ||||
| 112 | } elsif (ref($self->{'except'}) eq '') { | ||||
| 113 | $except{$self->{'except'}} = 1; | ||||
| 114 | } | ||||
| 115 | } | ||||
| 116 | $self->{_exceptions}->{only_hash} = \%only; | ||||
| 117 | $self->{_exceptions}->{only} = $only; | ||||
| 118 | $self->{_exceptions}->{except_hash} = \%except; | ||||
| 119 | $self->{_exceptions}->{except} = $except; | ||||
| 120 | |||||
| 121 | } | ||||
| 122 | |||||
| 123 | sub _is_legit { | ||||
| 124 | 1021 | 4.49ms | my $self = shift; | ||
| 125 | my $plugin = shift; | ||||
| 126 | my %only = %{$self->{_exceptions}->{only_hash}||{}}; | ||||
| 127 | my %except = %{$self->{_exceptions}->{except_hash}||{}}; | ||||
| 128 | my $only = $self->{_exceptions}->{only}; | ||||
| 129 | my $except = $self->{_exceptions}->{except}; | ||||
| 130 | |||||
| 131 | return 0 if (keys %only && !$only{$plugin} ); | ||||
| 132 | return 0 unless (!defined $only || $plugin =~ m!$only! ); | ||||
| 133 | |||||
| 134 | return 0 if (keys %except && $except{$plugin} ); | ||||
| 135 | return 0 if (defined $except && $plugin =~ m!$except! ); | ||||
| 136 | |||||
| 137 | return 1; | ||||
| 138 | } | ||||
| 139 | |||||
| 140 | # spent 93.5ms (635µs+92.8) within Module::Pluggable::Object::search_directories which was called 3 times, avg 31.2ms/call:
# 3 times (635µs+92.8ms) by Module::Pluggable::Object::plugins at line 58, avg 31.2ms/call | ||||
| 141 | 15 | 119µs | my $self = shift; | ||
| 142 | my @SEARCHDIR = @_; | ||||
| 143 | |||||
| 144 | my @plugins; | ||||
| 145 | # go through our @INC | ||||
| 146 | foreach my $dir (@SEARCHDIR) { | ||||
| 147 | 36 | 403µs | 72 | 93.0ms | push @plugins, $self->search_paths($dir); # spent 92.8ms making 36 calls to Module::Pluggable::Object::search_paths, avg 2.58ms/call
# spent 206µs making 36 calls to Regexp::DESTROY, avg 6µs/call |
| 148 | } | ||||
| 149 | return @plugins; | ||||
| 150 | } | ||||
| 151 | |||||
| 152 | |||||
| 153 | # spent 92.8ms (11.0+81.8) within Module::Pluggable::Object::search_paths which was called 36 times, avg 2.58ms/call:
# 36 times (11.0ms+81.8ms) by Module::Pluggable::Object::search_directories at line 147, avg 2.58ms/call | ||||
| 154 | 216 | 2.38ms | my $self = shift; | ||
| 155 | my $dir = shift; | ||||
| 156 | my @plugins; | ||||
| 157 | |||||
| 158 | my $file_regex = $self->{'file_regex'} || qr/\.pm$/; # spent 247µs making 36 calls to Module::Pluggable::Object::CORE:qr, avg 7µs/call | ||||
| 159 | |||||
| 160 | |||||
| 161 | # and each directory in our search path | ||||
| 162 | foreach my $searchpath (@{$self->{'search_path'}}) { | ||||
| 163 | # create the search directory in a cross platform goodness way | ||||
| 164 | 207 | 3.69ms | 96 | 13.0ms | my $sp = catdir($dir, (split /::/, $searchpath)); # spent 13.0ms making 96 calls to File::Spec::Functions::__ANON__[File/Spec/Functions.pm:43], avg 136µs/call |
| 165 | |||||
| 166 | # if it doesn't exist or it's not a dir then skip it | ||||
| 167 | next unless ( -e $sp && -d _ ); # Use the cached stat the second time # spent 1.01ms making 96 calls to Module::Pluggable::Object::CORE:ftis, avg 10µs/call
# spent 10µs making 5 calls to Module::Pluggable::Object::CORE:ftdir, avg 2µs/call | ||||
| 168 | |||||
| 169 | my @files = $self->find_files($sp); # spent 6.45ms making 5 calls to Module::Pluggable::Object::find_files, avg 1.29ms/call
# spent 22µs making 5 calls to Regexp::DESTROY, avg 4µs/call | ||||
| 170 | |||||
| 171 | # foreach one we've found | ||||
| 172 | foreach my $file (@files) { | ||||
| 173 | # untaint the file; accept .pm only | ||||
| 174 | 350 | 4.47ms | 50 | 771µs | next unless ($file) = ($file =~ /(.*$file_regex)$/); # spent 630µs making 25 calls to Module::Pluggable::Object::CORE:match, avg 25µs/call
# spent 142µs making 25 calls to Module::Pluggable::Object::CORE:regcomp, avg 6µs/call |
| 175 | # parse the file to get the name | ||||
| 176 | my ($name, $directory, $suffix) = fileparse($file, $file_regex); # spent 3.68ms making 25 calls to File::Basename::fileparse, avg 147µs/call | ||||
| 177 | |||||
| 178 | next if (!$self->{include_editor_junk} && $self->_is_editor_junk($name)); # spent 986µs making 25 calls to Module::Pluggable::Object::_is_editor_junk, avg 39µs/call | ||||
| 179 | |||||
| 180 | $directory = abs2rel($directory, $sp); # spent 28.8ms making 25 calls to File::Spec::Functions::__ANON__[File/Spec/Functions.pm:43], avg 1.15ms/call | ||||
| 181 | |||||
| 182 | # If we have a mixed-case package name, assume case has been preserved | ||||
| 183 | # correctly. Otherwise, root through the file to locate the case-preserved | ||||
| 184 | # version of the package name. | ||||
| 185 | my @pkg_dirs = (); | ||||
| 186 | 45 | 1.47ms | if ( $name eq lc($name) || $name eq uc($name) ) { | ||
| 187 | my $pkg_file = catfile($sp, $directory, "$name$suffix"); # spent 2.66ms making 9 calls to File::Spec::Functions::__ANON__[File/Spec/Functions.pm:43], avg 296µs/call | ||||
| 188 | open PKGFILE, "<$pkg_file" or die "search_paths: Can't open $pkg_file: $!"; # spent 533µs making 9 calls to Module::Pluggable::Object::CORE:open, avg 59µs/call | ||||
| 189 | my $in_pod = 0; | ||||
| 190 | 45 | 932µs | 9 | 326µs | while ( my $line = <PKGFILE> ) { # spent 326µs making 9 calls to Module::Pluggable::Object::CORE:readline, avg 36µs/call |
| 191 | $in_pod = 1 if $line =~ m/^=\w/; # spent 23µs making 9 calls to Module::Pluggable::Object::CORE:match, avg 3µs/call | ||||
| 192 | $in_pod = 0 if $line =~ /^=cut/; # spent 16µs making 9 calls to Module::Pluggable::Object::CORE:match, avg 2µs/call | ||||
| 193 | next if ($in_pod || $line =~ /^=cut/); # skip pod text # spent 14µs making 9 calls to Module::Pluggable::Object::CORE:match, avg 2µs/call | ||||
| 194 | next if $line =~ /^\s*#/; # and comments # spent 19µs making 9 calls to Module::Pluggable::Object::CORE:match, avg 2µs/call | ||||
| 195 | 27 | 215µs | 18 | 471µs | if ( $line =~ m/^\s*package\s+(.*::)?($name)\s*;/i ) { # spent 364µs making 9 calls to Module::Pluggable::Object::CORE:regcomp, avg 40µs/call
# spent 107µs making 9 calls to Module::Pluggable::Object::CORE:match, avg 12µs/call |
| 196 | @pkg_dirs = split /::/, $1; | ||||
| 197 | $name = $2; | ||||
| 198 | last; | ||||
| 199 | } | ||||
| 200 | } | ||||
| 201 | close PKGFILE; # spent 126µs making 9 calls to Module::Pluggable::Object::CORE:close, avg 14µs/call | ||||
| 202 | } | ||||
| 203 | |||||
| 204 | # then create the class name in a cross platform way | ||||
| 205 | $directory =~ s/^[a-z]://i if($^O =~ /MSWin32|dos/); # remove volume # spent 238µs making 25 calls to Module::Pluggable::Object::CORE:match, avg 10µs/call | ||||
| 206 | my @dirs = (); | ||||
| 207 | 75 | 1.10ms | if ($directory) { | ||
| 208 | ($directory) = ($directory =~ /(.*)/); # spent 167µs making 25 calls to Module::Pluggable::Object::CORE:match, avg 7µs/call | ||||
| 209 | @dirs = grep(length($_), splitdir($directory)) # spent 594µs making 25 calls to File::Spec::Functions::__ANON__[File/Spec/Functions.pm:43], avg 24µs/call | ||||
| 210 | unless $directory eq curdir(); | ||||
| 211 | for my $d (reverse @dirs) { | ||||
| 212 | my $pkg_dir = pop @pkg_dirs; | ||||
| 213 | last unless defined $pkg_dir; | ||||
| 214 | $d =~ s/\Q$pkg_dir\E/$pkg_dir/i; # Correct case | ||||
| 215 | } | ||||
| 216 | } else { | ||||
| 217 | $directory = ""; | ||||
| 218 | } | ||||
| 219 | my $plugin = join '::', $searchpath, @dirs, $name; | ||||
| 220 | |||||
| 221 | next unless $plugin =~ m!(?:[a-z\d]+)[a-z\d]!i; # spent 169µs making 25 calls to Module::Pluggable::Object::CORE:match, avg 7µs/call | ||||
| 222 | |||||
| 223 | my $err = $self->handle_finding_plugin($plugin); # spent 14.1ms making 25 calls to Module::Pluggable::Object::handle_finding_plugin, avg 565µs/call | ||||
| 224 | carp "Couldn't require $plugin : $err" if $err; | ||||
| 225 | |||||
| 226 | push @plugins, $plugin; | ||||
| 227 | } | ||||
| 228 | |||||
| 229 | # now add stuff that may have been in package | ||||
| 230 | # NOTE we should probably use all the stuff we've been given already | ||||
| 231 | # but then we can't unload it :( | ||||
| 232 | push @plugins, $self->handle_innerpackages($searchpath); # spent 7.20ms making 5 calls to Module::Pluggable::Object::handle_innerpackages, avg 1.44ms/call | ||||
| 233 | } # foreach $searchpath | ||||
| 234 | |||||
| 235 | return @plugins; | ||||
| 236 | } | ||||
| 237 | |||||
| 238 | # spent 986µs (835+150) within Module::Pluggable::Object::_is_editor_junk which was called 25 times, avg 39µs/call:
# 25 times (835µs+150µs) by Module::Pluggable::Object::search_paths at line 178, avg 39µs/call | ||||
| 239 | 150 | 1.23ms | my $self = shift; | ||
| 240 | my $name = shift; | ||||
| 241 | |||||
| 242 | # Emacs (and other Unix-y editors) leave temp files ending in a | ||||
| 243 | # tilde as a backup. | ||||
| 244 | return 1 if $name =~ /~$/; # spent 63µs making 25 calls to Module::Pluggable::Object::CORE:match, avg 3µs/call | ||||
| 245 | # Emacs makes these files while a buffer is edited but not yet | ||||
| 246 | # saved. | ||||
| 247 | return 1 if $name =~ /^\.#/; # spent 44µs making 25 calls to Module::Pluggable::Object::CORE:match, avg 2µs/call | ||||
| 248 | # Vim can leave these files behind if it crashes. | ||||
| 249 | return 1 if $name =~ /\.sw[po]$/; # spent 44µs making 25 calls to Module::Pluggable::Object::CORE:match, avg 2µs/call | ||||
| 250 | |||||
| 251 | return 0; | ||||
| 252 | } | ||||
| 253 | |||||
| 254 | # spent 18.5ms (1.86+16.7) within Module::Pluggable::Object::handle_finding_plugin which was called 53 times, avg 350µs/call:
# 28 times (1.05ms+3.35ms) by Module::Pluggable::Object::handle_innerpackages at line 297, avg 157µs/call
# 25 times (806µs+13.3ms) by Module::Pluggable::Object::search_paths at line 223, avg 565µs/call | ||||
| 255 | 237 | 1.58ms | my $self = shift; | ||
| 256 | my $plugin = shift; | ||||
| 257 | |||||
| 258 | return unless (defined $self->{'instantiate'} || $self->{'require'}); | ||||
| 259 | return unless $self->_is_legit($plugin); # spent 2.07ms making 42 calls to Module::Pluggable::Object::_is_legit, avg 49µs/call | ||||
| 260 | $self->_require($plugin); # spent 14.6ms making 36 calls to Module::Pluggable::Object::_require, avg 406µs/call | ||||
| 261 | } | ||||
| 262 | |||||
| 263 | # spent 6.45ms (478µs+5.97) within Module::Pluggable::Object::find_files which was called 5 times, avg 1.29ms/call:
# 5 times (478µs+5.97ms) by Module::Pluggable::Object::search_paths at line 169, avg 1.29ms/call | ||||
| 264 | 30 | 422µs | my $self = shift; | ||
| 265 | my $search_path = shift; | ||||
| 266 | my $file_regex = $self->{'file_regex'} || qr/\.pm$/; # spent 34µs making 5 calls to Module::Pluggable::Object::CORE:qr, avg 7µs/call | ||||
| 267 | |||||
| 268 | |||||
| 269 | # find all the .pm files in it | ||||
| 270 | # this isn't perfect and won't find multiple plugins per file | ||||
| 271 | #my $cwd = Cwd::getcwd; | ||||
| 272 | my @files = (); | ||||
| 273 | { # for the benefit of perl 5.6.1's Find, localize topic | ||||
| 274 | 10 | 118µs | local $_; | ||
| 275 | File::Find::find( { no_chdir => 1, | ||||
| 276 | # spent 1.26ms (958µs+298µs) within Module::Pluggable::Object::__ANON__[/usr/lib/perl5/5.10.1/Module/Pluggable/Object.pm:281] which was called 30 times, avg 42µs/call:
# 25 times (838µs+260µs) by File::Find::_find_dir at line 926 of File/Find.pm, avg 44µs/call
# 5 times (120µs+38µs) by File::Find::_find_dir at line 854 of File/Find.pm, avg 32µs/call | ||||
| 277 | # Inlined from File::Find::Rule C< name => '*.pm' > | ||||
| 278 | 80 | 1.36ms | 60 | 250µs | return unless $File::Find::name =~ /$file_regex/; # spent 141µs making 30 calls to Module::Pluggable::Object::CORE:match, avg 5µs/call
# spent 109µs making 30 calls to Module::Pluggable::Object::CORE:regcomp, avg 4µs/call |
| 279 | (my $path = $File::Find::name) =~ s#^\\./##; # spent 48µs making 25 calls to Module::Pluggable::Object::CORE:subst, avg 2µs/call | ||||
| 280 | push @files, $path; | ||||
| 281 | } | ||||
| 282 | }, $search_path ); # spent 5.92ms making 5 calls to File::Find::find, avg 1.18ms/call | ||||
| 283 | } | ||||
| 284 | #chdir $cwd; | ||||
| 285 | return @files; | ||||
| 286 | |||||
| 287 | } | ||||
| 288 | |||||
| 289 | # spent 14.7ms (1.55+13.2) within Module::Pluggable::Object::handle_innerpackages which was called 13 times, avg 1.13ms/call:
# 8 times (1.13ms+6.39ms) by Module::Pluggable::Object::plugins at line 59, avg 941µs/call
# 5 times (412µs+6.79ms) by Module::Pluggable::Object::search_paths at line 232, avg 1.44ms/call | ||||
| 290 | 78 | 568µs | my $self = shift; | ||
| 291 | return () if (exists $self->{inner} && !$self->{inner}); | ||||
| 292 | |||||
| 293 | my $path = shift; | ||||
| 294 | my @plugins; | ||||
| 295 | |||||
| 296 | foreach my $plugin (Devel::InnerPackage::list_packages($path)) { # spent 8.78ms making 13 calls to Devel::InnerPackage::list_packages, avg 675µs/call | ||||
| 297 | 56 | 855µs | 28 | 4.40ms | my $err = $self->handle_finding_plugin($plugin); # spent 4.40ms making 28 calls to Module::Pluggable::Object::handle_finding_plugin, avg 157µs/call |
| 298 | #next if $err; | ||||
| 299 | #next unless $INC{$plugin}; | ||||
| 300 | push @plugins, $plugin; | ||||
| 301 | } | ||||
| 302 | return @plugins; | ||||
| 303 | |||||
| 304 | } | ||||
| 305 | |||||
| 306 | |||||
| 307 | # spent 14.6ms (10.6+4.00) within Module::Pluggable::Object::_require which was called 36 times, avg 406µs/call:
# 36 times (10.6ms+4.00ms) by Module::Pluggable::Object::handle_finding_plugin at line 260, avg 406µs/call | ||||
| 308 | 180 | 3.14ms | my $self = shift; | ||
| 309 | my $pack = shift; | ||||
| 310 | local $@; | ||||
| 311 | 1 | 2.72ms | eval "CORE::require $pack"; | ||
| 312 | return $@; | ||||
| 313 | } | ||||
| 314 | |||||
| 315 | |||||
| 316 | 1 | 6µs | 1; | ||
| 317 | |||||
| 318 | =pod | ||||
| 319 | |||||
| 320 | =head1 NAME | ||||
| 321 | |||||
| 322 | Module::Pluggable::Object - automatically give your module the ability to have plugins | ||||
| 323 | |||||
| 324 | =head1 SYNOPSIS | ||||
| 325 | |||||
| 326 | |||||
| 327 | Simple use Module::Pluggable - | ||||
| 328 | |||||
| 329 | package MyClass; | ||||
| 330 | use Module::Pluggable::Object; | ||||
| 331 | |||||
| 332 | my $finder = Module::Pluggable::Object->new(%opts); | ||||
| 333 | print "My plugins are: ".join(", ", $finder->plugins)."\n"; | ||||
| 334 | |||||
| 335 | =head1 DESCRIPTION | ||||
| 336 | |||||
| 337 | Provides a simple but, hopefully, extensible way of having 'plugins' for | ||||
| 338 | your module. Obviously this isn't going to be the be all and end all of | ||||
| 339 | solutions but it works for me. | ||||
| 340 | |||||
| 341 | Essentially all it does is export a method into your namespace that | ||||
| 342 | looks through a search path for .pm files and turn those into class names. | ||||
| 343 | |||||
| 344 | Optionally it instantiates those classes for you. | ||||
| 345 | |||||
| 346 | This object is wrapped by C<Module::Pluggable>. If you want to do something | ||||
| 347 | odd or add non-general special features you're probably best to wrap this | ||||
| 348 | and produce your own subclass. | ||||
| 349 | |||||
| 350 | =head1 OPTIONS | ||||
| 351 | |||||
| 352 | See the C<Module::Pluggable> docs. | ||||
| 353 | |||||
| 354 | =head1 AUTHOR | ||||
| 355 | |||||
| 356 | Simon Wistow <simon@thegestalt.org> | ||||
| 357 | |||||
| 358 | =head1 COPYING | ||||
| 359 | |||||
| 360 | Copyright, 2006 Simon Wistow | ||||
| 361 | |||||
| 362 | Distributed under the same terms as Perl itself. | ||||
| 363 | |||||
| 364 | =head1 BUGS | ||||
| 365 | |||||
| 366 | None known. | ||||
| 367 | |||||
| 368 | =head1 SEE ALSO | ||||
| 369 | |||||
| 370 | L<Module::Pluggable> | ||||
| 371 | |||||
| 372 | =cut | ||||
| 373 | |||||
# spent 126µs within Module::Pluggable::Object::CORE:close which was called 9 times, avg 14µs/call:
# 9 times (126µs+0s) by Module::Pluggable::Object::search_paths at line 201 of Module/Pluggable/Object.pm, avg 14µs/call | |||||
# spent 10µs within Module::Pluggable::Object::CORE:ftdir which was called 5 times, avg 2µs/call:
# 5 times (10µs+0s) by Module::Pluggable::Object::search_paths at line 167 of Module/Pluggable/Object.pm, avg 2µs/call | |||||
# spent 1.01ms within Module::Pluggable::Object::CORE:ftis which was called 96 times, avg 10µs/call:
# 96 times (1.01ms+0s) by Module::Pluggable::Object::search_paths at line 167 of Module/Pluggable/Object.pm, avg 10µs/call | |||||
# spent 1.67ms within Module::Pluggable::Object::CORE:match which was called 250 times, avg 7µs/call:
# 30 times (141µs+0s) by Module::Pluggable::Object::__ANON__[/usr/lib/perl5/5.10.1/Module/Pluggable/Object.pm:281] at line 278 of Module/Pluggable/Object.pm, avg 5µs/call
# 25 times (630µs+0s) by Module::Pluggable::Object::search_paths at line 174 of Module/Pluggable/Object.pm, avg 25µs/call
# 25 times (238µs+0s) by Module::Pluggable::Object::search_paths at line 205 of Module/Pluggable/Object.pm, avg 10µs/call
# 25 times (169µs+0s) by Module::Pluggable::Object::search_paths at line 221 of Module/Pluggable/Object.pm, avg 7µs/call
# 25 times (167µs+0s) by Module::Pluggable::Object::search_paths at line 208 of Module/Pluggable/Object.pm, avg 7µs/call
# 25 times (63µs+0s) by Module::Pluggable::Object::_is_editor_junk at line 244 of Module/Pluggable/Object.pm, avg 3µs/call
# 25 times (44µs+0s) by Module::Pluggable::Object::_is_editor_junk at line 247 of Module/Pluggable/Object.pm, avg 2µs/call
# 25 times (44µs+0s) by Module::Pluggable::Object::_is_editor_junk at line 249 of Module/Pluggable/Object.pm, avg 2µs/call
# 9 times (107µs+0s) by Module::Pluggable::Object::search_paths at line 195 of Module/Pluggable/Object.pm, avg 12µs/call
# 9 times (23µs+0s) by Module::Pluggable::Object::search_paths at line 191 of Module/Pluggable/Object.pm, avg 3µs/call
# 9 times (19µs+0s) by Module::Pluggable::Object::search_paths at line 194 of Module/Pluggable/Object.pm, avg 2µs/call
# 9 times (16µs+0s) by Module::Pluggable::Object::search_paths at line 192 of Module/Pluggable/Object.pm, avg 2µs/call
# 9 times (14µs+0s) by Module::Pluggable::Object::search_paths at line 193 of Module/Pluggable/Object.pm, avg 2µs/call | |||||
# spent 533µs within Module::Pluggable::Object::CORE:open which was called 9 times, avg 59µs/call:
# 9 times (533µs+0s) by Module::Pluggable::Object::search_paths at line 188 of Module/Pluggable/Object.pm, avg 59µs/call | |||||
# spent 281µs within Module::Pluggable::Object::CORE:qr which was called 41 times, avg 7µs/call:
# 36 times (247µs+0s) by Module::Pluggable::Object::search_paths at line 158 of Module/Pluggable/Object.pm, avg 7µs/call
# 5 times (34µs+0s) by Module::Pluggable::Object::find_files at line 266 of Module/Pluggable/Object.pm, avg 7µs/call | |||||
# spent 326µs within Module::Pluggable::Object::CORE:readline which was called 9 times, avg 36µs/call:
# 9 times (326µs+0s) by Module::Pluggable::Object::search_paths at line 190 of Module/Pluggable/Object.pm, avg 36µs/call | |||||
# spent 614µs within Module::Pluggable::Object::CORE:regcomp which was called 64 times, avg 10µs/call:
# 30 times (109µs+0s) by Module::Pluggable::Object::__ANON__[/usr/lib/perl5/5.10.1/Module/Pluggable/Object.pm:281] at line 278 of Module/Pluggable/Object.pm, avg 4µs/call
# 25 times (142µs+0s) by Module::Pluggable::Object::search_paths at line 174 of Module/Pluggable/Object.pm, avg 6µs/call
# 9 times (364µs+0s) by Module::Pluggable::Object::search_paths at line 195 of Module/Pluggable/Object.pm, avg 40µs/call | |||||
# spent 48µs within Module::Pluggable::Object::CORE:subst which was called 25 times, avg 2µs/call:
# 25 times (48µs+0s) by Module::Pluggable::Object::__ANON__[/usr/lib/perl5/5.10.1/Module/Pluggable/Object.pm:281] at line 279 of Module/Pluggable/Object.pm, avg 2µs/call |