| 1 | 4 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 2 | 4 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 3 | |||||||||||||||
| 4 | package Test::Class::Load; | ||||||||||||||
| 5 | |||||||||||||||
| 6 | 4 | ▶ | use Test::Class; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 7 | 4 | ▶ | use File::Find; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 8 | 4 | ▶ | use File::Spec; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 9 | 4 | ▶ | use Module::Runtime 'require_module'; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 10 | |||||||||||||||
| 11 | 19 | our $VERSION = '0.52'; | |||||||||||||
| 12 | |||||||||||||||
| 13 | # Override to get your own filter | ||||||||||||||
| 14 | 5 | ▶ | sub is_test_class { | ||||||||||||
|
Subroutine
is_test_class: called CC=2 SCAR=6.9
Pod
documented
Pod
documented
| |||||||||||||||
| 15 | 5 | my ( $class, $file, $dir ) = @_; | |||||||||||||
| 16 | # By default, we only care about .pm files | ||||||||||||||
| 17 | 5 | ▶ | if ($file =~ /\.pm$/) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 18 | 2 | return 1; | |||||||||||||
| 19 | } | ||||||||||||||
| 20 | 3 | return; | |||||||||||||
| 21 | } | ||||||||||||||
| 22 | |||||||||||||||
| 23 | 19 | my %Added_to_INC; | |||||||||||||
| 24 | 15 | ▶ | sub _load { | ||||||||||||
|
Subroutine
_load: called CC=3 SCAR=11.0
| |||||||||||||||
| 25 | 15 | my ( $class, $file, $dir ) = @_; | |||||||||||||
| 26 | 15 | $file =~ s{\.pm$}{}; # remove .pm extension | |||||||||||||
| 27 | 9 | $file =~ s{\\}{/}g; # to make win32 happy | |||||||||||||
| 28 | 11 | $dir =~ s{\\}{/}g; # to make win32 happy | |||||||||||||
| 29 | 5 | $file =~ s/^$dir//; | |||||||||||||
| 30 | 5 | my $_package = join '::' => grep $_ => File::Spec->splitdir( $file ); | |||||||||||||
| 31 | |||||||||||||||
| 32 | # untaint that puppy! | ||||||||||||||
| 33 | 5 | my ( $package ) = $_package =~ /^([[:word:]]+(?:::[[:word:]]+)*)$/; | |||||||||||||
| 34 | |||||||||||||||
| 35 | # Filter out bad classes (mainly this means things in .svn and similar) | ||||||||||||||
| 36 | 5 | ▶ | return unless defined $package; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 37 | |||||||||||||||
| 38 | 5 | ▶ | unshift @INC => $dir unless $Added_to_INC{ $dir }++; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 39 | 5 | require_module($package); | |||||||||||||
| 40 | } | ||||||||||||||
| 41 | |||||||||||||||
| 42 | 7 | ▶ | sub import { | ||||||||||||
|
Subroutine
import: called CC=2 SCAR=6.9
| |||||||||||||||
| 43 | 7 | my ( $class, @directories ) = @_; | |||||||||||||
| 44 | 7 | my @test_classes; | |||||||||||||
| 45 | |||||||||||||||
| 46 | 7 | foreach my $dir ( @directories ) { | |||||||||||||
| 47 | 6 | $dir = File::Spec->catdir( split '/', $dir ); | |||||||||||||
| 48 | find( | ||||||||||||||
| 49 | { no_chdir => 1, | ||||||||||||||
| 50 | 15 | ▶ | wanted => sub { | ||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||
| 51 | 19 | my @args = ($File::Find::name, $dir); | |||||||||||||
| 52 | 19 | ▶ | if ($class->is_test_class(@args)) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 53 | 11 | $class->_load(@args); | |||||||||||||
| 54 | } | ||||||||||||||
| 55 | }, | ||||||||||||||
| 56 | }, | ||||||||||||||
| 57 | 6 | $dir | |||||||||||||
| 58 | ); | ||||||||||||||
| 59 | } | ||||||||||||||
| 60 | } | ||||||||||||||
| 61 | |||||||||||||||
| 62 | 6 | 1; | |||||||||||||
| 63 | |||||||||||||||
| 64 | __END__ | ||||||||||||||