Moose/Load.pm

filter: Statementstmt 100% 66 / 66 Branchbran 90.0% 9 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 22 / 22 Podpod 100% 1 / 1 totaltotal 98.9% 98 / 99 CC 7 SCAR 3.7
CC
7
Cov
99%
_load
4.0
is_test_class
2.0
import
2.0
CRAP 1.5
« Moose/Role/AutoUse.pm ↑ Summary Moose/Role/HasTimeReport.pm »
1 package Test::Class::Moose::Load;
2  
3 # ABSTRACT: Load L<Test::Class::Moose> classes automatically.
4  
5 45 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 44 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 43 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 30 our $VERSION = '1.00';
10  
11 41 ▶use File::Find;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 41 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 # Override to get your own filter
15 387 ▶sub is_test_class {
Subroutine is_test_class: called CC=2 SCAR=6.9
Pod documented
16 387 my ( undef, $file, undef ) = @_;
17  
18 # By default, we only care about .pm files
19 387 ▶ if ( $file =~ /\.pm$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($file =~ /\.pm$/) 184 191 375
20 196 return 1;
21 }
22 203 return;
23 }
24  
25 30 my %Added_to_INC;
26  
27 196 ▶sub _load {
Subroutine _load: called CC=4 SCAR=13.9
28 196 my ( $class, $file, $dir ) = @_;
29  
30 196 $file =~ s{\.pm$}{}; # remove .pm extension
31 185 $file =~ s{\\}{/}g; # to make win32 happy
32 185 $dir =~ s{\\}{/}g; # to make win32 happy
33 185 $file =~ s/^\Q$dir\E//;
34 185 my $_package = join '::', grep {$_} File::Spec->splitdir($file);
35  
36 # untaint that puppy!
37 185 my ($package) = $_package =~ /^([[:word:]]+(?:::[[:word:]]+)*)$/;
38  
39 # Filter out bad classes (mainly this means things in .svn and similar)
40 185 ▶ return unless defined $package;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $package 0 184 184
41  
42 185 ▶ unshift @INC => $dir unless $Added_to_INC{$dir}++;
Branch: 1 branch
BranchTrueFalseTotal
unless $Added_to_INC{$dir}++ 73 111 184
43  
44 {
45 185 ▶ local $SIG{__DIE__} = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
46 17 undef $SIG{__DIE__};
47 17 require Carp;
48 17 local $Carp::CarpLevel = $Carp::CarpLevel + 1;
49 17 Carp::confess(@_);
50 185 };
51  
52 # either "require" it or "use" it with no import list. Otherwise, this
53 # module will inherit from Test::Class::Moose and break everything.
54  
55 ## no critic (BuiltinFunctions::ProhibitStringyEval, ErrorHandling::RequireCheckingReturnValueOfEval)
56 41 ▶ eval "use $package ()";
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
57 }
58 185 ▶ die $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 1 183 184
59 }
60  
61 38 ▶sub import {
Subroutine import: called CC=2 SCAR=6.9
62 38 my ( $class, @directories ) = @_;
63  
64 38 foreach my $dir (@directories) {
65 82 $dir = File::Spec->catdir( split /\//, $dir );
66 find(
67 { no_chdir => 1,
68 376 ▶ wanted => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
69 376 my @args = ( $File::Find::name, $dir );
70 376 ▶ if ( $class->is_test_class(@args) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($class->is_test_class(@args)) 184 191 375
71 185 $class->_load(@args);
72 }
73 },
74 },
75 82 $dir
76 );
77 }
78 }
79  
80 30 1;
81  
82 __END__
« Moose/Role/AutoUse.pm ↑ Summary Moose/Role/HasTimeReport.pm »