| 1 | package all; | ||||||||||
| 2 | |||||||||||
| 3 | 4 | ▶ | use 5.006; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 4 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 4 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 4 | ▶ | use File::Spec (); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 4 | ▶ | use File::Find (); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 4 | our $VERSION = 0.51_01; | |||||||||
| 11 | |||||||||||
| 12 | 4 | ▶ | sub import { | ||||||||
|
Subroutine
import: called CC=5 SCAR=16.1
| |||||||||||
| 13 | 4 | my $class = shift; | |||||||||
| 14 | 4 | my $of = shift; | |||||||||
| 15 | 4 | my $args = [ @_ ]; | |||||||||
| 16 | 4 | ▶ | if ($of ne 'of') { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 17 | 2 | unshift @$args, $of; | |||||||||
| 18 | } | ||||||||||
| 19 | 4 | my $caller = caller(); | |||||||||
| 20 | 4 | foreach my $arg (@$args) { | |||||||||
| 21 | 6 | my $modules = _find_modules( $arg ); | |||||||||
| 22 | 6 | foreach my $module (@$modules) { | |||||||||
| 23 | 18 | my $package = $module->{ module }; | |||||||||
| 24 | 18 | eval { | |||||||||
| 25 | 18 | require $module->{ path }; | |||||||||
| 26 | 18 | $package->import; | |||||||||
| 27 | }; | ||||||||||
| 28 | 18 | ▶ | if ($@) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 29 | 0 | warn( $@ ); | |||||||||
| 30 | } | ||||||||||
| 31 | } | ||||||||||
| 32 | } | ||||||||||
| 33 | 4 | 1; | |||||||||
| 34 | } | ||||||||||
| 35 | |||||||||||
| 36 | 6 | ▶ | sub _find_modules { | ||||||||
|
Subroutine
_find_modules: called CC=5 SCAR=16.1
| |||||||||||
| 37 | 6 | my $module = shift; | |||||||||
| 38 | 6 | my $moduledir = _module_to_file( $module ); | |||||||||
| 39 | 6 | my $list = []; | |||||||||
| 40 | |||||||||||
| 41 | 6 | foreach my $incdir (@INC) { | |||||||||
| 42 | 72 | ▶ | next if ref $incdir; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 43 | |||||||||||
| 44 | 72 | my $dir = File::Spec->catfile($incdir, $moduledir); | |||||||||
| 45 | 72 | ▶ | next unless -d $dir; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 46 | |||||||||||
| 47 | 6 | my @files = (); | |||||||||
| 48 | File::Find::find({ | ||||||||||
| 49 | 24 | ▶ | wanted => sub { | ||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||
| 50 | 24 | ▶ | return unless $File::Find::name =~ /\.pm$/; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 51 | 18 | push @files, $File::Find::name; | |||||||||
| 52 | }, | ||||||||||
| 53 | 6 | no_chdir => 1, | |||||||||
| 54 | }, $dir); | ||||||||||
| 55 | |||||||||||
| 56 | 6 | foreach my $absfile (@files) { | |||||||||
| 57 | 18 | my $relfile = File::Spec->abs2rel( $absfile, $incdir ); | |||||||||
| 58 | 18 | push @$list, { | |||||||||
| 59 | path => $relfile, | ||||||||||
| 60 | module => _file_to_module( $relfile ) | ||||||||||
| 61 | }; | ||||||||||
| 62 | } | ||||||||||
| 63 | } | ||||||||||
| 64 | 6 | return $list; | |||||||||
| 65 | } | ||||||||||
| 66 | |||||||||||
| 67 | 18 | ▶ | sub _file_to_module { | ||||||||
|
Subroutine
_file_to_module: called CC=1 SCAR=0.0
| |||||||||||
| 68 | 18 | my $file = shift; | |||||||||
| 69 | 18 | $file =~ s/\.pm$//; | |||||||||
| 70 | 18 | my @list = File::Spec->splitpath( $file ); | |||||||||
| 71 | 18 | shift @list; | |||||||||
| 72 | 18 | return join('::', @list) | |||||||||
| 73 | } | ||||||||||
| 74 | |||||||||||
| 75 | 6 | ▶ | sub _module_to_file { | ||||||||
|
Subroutine
_module_to_file: called CC=1 SCAR=0.0
| |||||||||||
| 76 | 6 | my $module = shift; | |||||||||
| 77 | 6 | $module =~ s{::\*?$}{}; | |||||||||
| 78 | 6 | $module =~ s{::}{/}g; | |||||||||
| 79 | 6 | return $module; | |||||||||
| 80 | } | ||||||||||
| 81 | |||||||||||
| 82 | 4 | 1; | |||||||||
| 83 | |||||||||||
| 84 | __END__ | ||||||||||