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