| 1 | package Namespace::Subroutines; | ||||||||||||||||||||||||||||||||
| 2 | 2 | ▶ | use 5.010; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use attributes; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use Carp qw( carp ); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use File::Find (); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use feature 'say'; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||
| 10 | 2 | our $VERSION = '0.01'; | |||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||
| 12 | 2 | my %skip = ( | |||||||||||||||||||||||||||||||
| 13 | AUTOLOAD => 1, | ||||||||||||||||||||||||||||||||
| 14 | BEGIN => 1, | ||||||||||||||||||||||||||||||||
| 15 | MODIFY_CODE_ATTRIBUTES => 1, | ||||||||||||||||||||||||||||||||
| 16 | FETCH_CODE_ATTRIBUTES => 1, | ||||||||||||||||||||||||||||||||
| 17 | ); | ||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||
| 19 | sub find { | ||||||||||||||||||||||||||||||||
| 20 | 1 | ▶ | my ( $ns, $cb ) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
find: called CC=15 SCAR=28.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||
| 22 | # 'My::App::Controller' -> 'My/App/Controller' | ||||||||||||||||||||||||||||||||
| 23 | 1 | my $ns2 = $ns =~ s{::}{/}gr; | |||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||
| 25 | 1 | my @modules; | |||||||||||||||||||||||||||||||
| 26 | 1 | foreach my $path (@INC) { | |||||||||||||||||||||||||||||||
| 27 | 7 | ▶ | next unless -d $path; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 28 | File::Find::find( | ||||||||||||||||||||||||||||||||
| 29 | sub { | ||||||||||||||||||||||||||||||||
| 30 | 21501 | ▶ | return unless /\.pm$/; | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 31 | 1969 | my $name = $File::Find::name =~ s{$path/}{}r; | |||||||||||||||||||||||||||||||
| 32 | 1969 | ▶ | return unless $name =~ /^$ns2/; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 33 | 1 | push @modules, [ $name, $File::Find::name ]; | |||||||||||||||||||||||||||||||
| 34 | }, | ||||||||||||||||||||||||||||||||
| 35 | 7 | $path | |||||||||||||||||||||||||||||||
| 36 | ); | ||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||
| 39 | 1 | foreach my $m (@modules) { | |||||||||||||||||||||||||||||||
| 40 | 1 | my ( $modname, $path ) = @$m; | |||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||
| 42 | # 'Data/Dumper.pm' -> qw(Data Dumper.pm) | ||||||||||||||||||||||||||||||||
| 43 | 1 | my @a = split( m{/}, $modname ); | |||||||||||||||||||||||||||||||
| 44 | 1 | pop @a; # qw(Data) | |||||||||||||||||||||||||||||||
| 45 | 1 | my $namespace = join( '/', @a ); # 'Data' | |||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||
| 47 | # 'My/App/Controller/Users.pm', 'My/App/Controller/Inventory.pm', etc. | ||||||||||||||||||||||||||||||||
| 48 | 1 | ▶ | next unless $namespace =~ /^$ns2/; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 49 | 1 | ▶ | require $modname unless defined $INC{$modname}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||
| 51 | 1 | my $module = $modname; # 'My/App/Controller/Users.pm' | |||||||||||||||||||||||||||||||
| 52 | 1 | $module =~ s{\.pm$}{}; # 'My/App/Controller/Users' | |||||||||||||||||||||||||||||||
| 53 | 1 | $module =~ s{/}{::}g; # 'My::App::Controller::Users' | |||||||||||||||||||||||||||||||
| 54 | 1 | $module .= '::'; # 'My::App::Controller::Users::' | |||||||||||||||||||||||||||||||
| 55 | 1 | my $table = '%' . $module; # '%My::App::Controller::Users::' | |||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||
| 57 | ## no critic (BuiltinFunctions::ProhibitStringyEval) | ||||||||||||||||||||||||||||||||
| 58 | 1 | my @symbols = split( m{\|}, eval "join('|', keys $table)" ); | |||||||||||||||||||||||||||||||
| 59 | 1 | my @subroutines = grep { defined &{ $module . $_ } } @symbols; | |||||||||||||||||||||||||||||||
| 60 | 1 | my %subroutines; | |||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||
| 62 | 1 | ▶ | open my $fh, '<', $path or ( carp "unable to open $!" and next ); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition20%1/5
open(my $fh, '<', $path) || carp("unable to open $!") && (next)
carp("unable to open $!") and next
MC/DC0%0/2
open(my $fh, '<', $path) || carp("unable to open $!") && (next)
open(my $fh, '<', $path)
carp("unable to open $!")
Truth table33%1/3
A || B
A= open(my $fh, '<', $path)B= carp("unable to open $!")
| |||||||||||||||||||||||||||||||||
| 63 | 1 | ▶ | while ( my $line = <$fh> ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 64 | 10 | ▶ | next unless $line =~ /^sub\s+(\w+)[\:\(\s]/; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 65 | 2 | $subroutines{$1} = 1; | |||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||
| 67 | 1 | ▶ | close $fh or ( carp "error closing $!" and next ); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition20%1/5
close $fh || carp("error closing $!") && (next)
carp("error closing $!") and next
MC/DC0%0/2
close $fh || carp("error closing $!") && (next)
close $fh
carp("error closing $!")
Truth table33%1/3
A || B
A= close $fhB= carp("error closing $!")
| |||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||
| 69 | # 'My::App::Controller::Users::' -> 'Users' | ||||||||||||||||||||||||||||||||
| 70 | 1 | $module =~ s{^$ns\::(.+)::$}{$1}; | |||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||
| 72 | 1 | foreach my $sub (@subroutines) { | |||||||||||||||||||||||||||||||
| 73 | 4 | ▶ | next if $skip{$sub}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 74 | 4 | ▶ | next unless $subroutines{$sub}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 75 | 2 | my $name = join( '::', $ns, $module, $sub ); | |||||||||||||||||||||||||||||||
| 76 | 2 | my $ref = \&$name; | |||||||||||||||||||||||||||||||
| 77 | 2 | my @attrs = attributes::get( \&$name ); | |||||||||||||||||||||||||||||||
| 78 | 2 | $cb->( [ split( /::/, $module ) ], $sub, $ref, \@attrs ); | |||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||
| 83 | 2 | 1; | |||||||||||||||||||||||||||||||
| 84 | __END__ | ||||||||||||||||||||||||||||||||