NCC.pm

filter: Statementstmt 98.8% 87 / 88 Branchbran 73.0% 19 / 26 Conditioncond 66.6% 8 / 12 MC/DCmcdc 50.0% 4 / 8 Subroutinesub 94.1% 16 / 17 Podpod 0.0% 0 / 4 totaltotal 86.4% 134 / 155 CC 18 SCAR 14.8
CC
18
Cov
90%
import
8.6
install_warpcore
7.0
make_pm
3.0
CRAP 4.4
↑ Summary NCC/WarpCore.pm »
1 package NCC;
2 3 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 $NCC::AUTHORITY = 'cpan:GETTY';
4 }
5 {
6 3 $NCC::VERSION = '0.001';
7 }
8 # ABSTRACT: True enterprise application framework
9  
10 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 3 ▶use Class::Load ':all';
Subroutine BEGIN: called CC=1 SCAR=0.0
13 3 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
14 3 ▶use File::Temp qw( tempdir );
Subroutine BEGIN: called CC=1 SCAR=0.0
15 3 ▶use File::Spec::Functions;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 3 ▶use File::Path qw( make_path );
Subroutine BEGIN: called CC=1 SCAR=0.0
17 3 ▶use lib ();
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 3 our %WarpCores;
20 3 my %files;
21  
22 my $tempdir = defined $ENV{'NCC_TEMPDIR'}
23 3 ▶ ? $ENV{'NCC_TEMPDIR'} : tempdir( CLEANUP => 1 );
Branch: 1 branch
BranchTrueFalseTotal
defined $ENV{'NCC_TEMPDIR'} ? : 0 3 3
24 3 lib->import($tempdir);
25  
26 3 our %INCC;
27  
28 4 ▶sub import {
Subroutine import: called CC=8 SCAR=21.5
29 4 my ( $class, @args ) = @_;
30 4 my $target = caller;
31 4 ▶ if (scalar @args == 1 && $args[0] eq 'import') {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @args == 1 and $args[0] eq "import") 1 3 4
Condition66%2/3
scalar @args == 1 and $args[0] eq "import"
!ll&&!rl&&r
301
MC/DC50%1/2
scalar @args == 1 and $args[0] eq "import"
scalar @args == 1 $args[0] eq "import"
Truth table66%2/3
A and B
A= scalar @args == 1B= $args[0] eq "import"
ABresult
0X0
100
111
32 {
33 3 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
34 1 *{$target.'::import'} = \&import;
35 }
36 1 return;
37 }
38 3 ▶ return if defined $WarpCores{$target};
Branch: 1 branch
BranchTrueFalseTotal
if defined $NCC::WarpCores{$target} 0 3 3
39 3 ▶ my $warpcore_class = scalar @args == 2 && $args[0] eq 'WarpCore'
Branch: 1 branch
BranchTrueFalseTotal
scalar @args == 2 && $args[0] eq 'WarpCore' ? : 0 3 3
Condition33%1/3
scalar @args == 2 and $args[0] eq "WarpCore"
!ll&&!rl&&r
300
MC/DC0%0/2
scalar @args == 2 and $args[0] eq "WarpCore"
scalar @args == 2 $args[0] eq "WarpCore"
Truth table33%1/3
A and B
A= scalar @args == 2B= $args[0] eq "WarpCore"
ABresult
0X0
100
111
40 ? $args[1] : $class.'::WarpCore';
41 3 load_class($warpcore_class);
42 3 ▶ croak "WarpCore can't be instantiated" unless $warpcore_class->can('new');
Branch: 1 branch
BranchTrueFalseTotal
unless $warpcore_class->can("new") 0 3 3
43 3 ▶ croak "WarpCore needs at least an energize function" unless $warpcore_class->can('energize');
Branch: 1 branch
BranchTrueFalseTotal
unless $warpcore_class->can("energize") 0 3 3
44 3 $WarpCores{$target} = $warpcore_class->new(@args);
45 3 $WarpCores{$target}->energize($target);
46 }
47  
48 326 ▶sub find_in_inc {
Subroutine find_in_inc: called CC=3 SCAR=11.0
Pod undocumented
49 326 my $file = $_[0];
50 326 for (@INC) {
51 2802 my $inc = catfile($_,$file);
52 2802 ▶ return $inc if -f $inc;
Branch: 1 branch
BranchTrueFalseTotal
if -f $inc 2 2800 2802
53 }
54 }
55  
56 2 ▶sub make_pm {
Subroutine make_pm: called CC=3 SCAR=11.0
Pod undocumented
57 2 my ( $module, $src_file, $target_file ) = @_;
58 2 local $/;
59 2 ▶ open my $src_fh, "<", $src_file or croak "could not open $src_file: $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $src_fh, "<", $src_file or croak("could not open ${src_file}: $!") 2 0 2
60 2 my $src = <$src_fh>;
61 2 close $src_fh;
62 2 my ( undef, $target_dir, undef ) = File::Spec->splitpath( $target_file );
63 2 make_path($target_dir);
64 2 ▶ open my $target_fh, ">", $target_file or croak "could not open $target_file: $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $target_fh, ">", $target_file or croak("could not open ${target_file}: $!") 2 0 2
65 2 print $target_fh "package ".$module.";\n\n\n";
66 2 print $target_fh $src;
67 2 print $target_fh "\n\n\n1;";
68 2 close $target_fh;
69 }
70  
71 0 ▶sub engineering { $WarpCores{$_[0]} }
Subroutine engineering: not called CC=1 SCAR=6.9
Pod undocumented
72  
73 2136 ▶sub install_warpcore {
Subroutine install_warpcore: called CC=7 SCAR=19.5
Pod undocumented
74 2136 my $file = $_[0];
75 2136 ▶ return CORE::require( $file ) if defined $files{$file} or $file !~ m/\.pm$/;
Branch: 1 branch
BranchTrueFalseTotal
if defined $files{$file} or not $file =~ /\.pm$/ 1810 326 2136
Condition100%3/3
defined $files{$file} or not $file =~ /\.pm$/
l!l&&r!l&&!r
176941326
MC/DC100%2/2
defined $files{$file} or not $file =~ /\.pm$/
defined $files{$file} not $file =~ /\.pm$/
Truth table100%3/3
A or not(B)
A= defined $files{$file}B= not $file =~ /\.pm$/
ABresult
1X1
011
000
76 326 $files{$file} = 1;
77 326 ( my $ncc_file = $file ) =~ s/\.pm$/.ncc/g;
78 326 ( my $module = $file ) =~ s/\//::/g;
79 326 $module =~ s/\.pm$//g;
80 326 ▶ if (my $ncc = find_in_inc($ncc_file)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $ncc = find_in_inc($ncc_file)) 2 324 326
81 2 $INCC{$file} = $ncc;
82 2 make_pm($module,$ncc,catfile($tempdir,$file));
83 }
84 326 my $has_warp;
85 326 ▶ if (my @matches = grep { $module =~ m/^${_}::/ } sort { length($b) <=> length($a) } keys %WarpCores) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@matches) = grep({$module =~ /^$_::/;} (sort {length $b <=> length $a;} keys %NCC::WarpCores))) 2 324 326
86 2 $WarpCores{$module} = $WarpCores{$matches[0]};
87 2 $WarpCores{$module}->energize($module);
88 2 $has_warp = 1;
89 }
90 326 CORE::require( $file );
91 322 ▶ if ($has_warp && $WarpCores{$module}->can('enervate')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($has_warp and $NCC::WarpCores{$module}->can("enervate")) 2 320 322
Condition66%2/3
$has_warp and $NCC::WarpCores{$module}->can("enervate")
!ll&&!rl&&r
32002
MC/DC50%1/2
$has_warp and $NCC::WarpCores{$module}->can("enervate")
$has_warp $NCC::WarpCores{$module}->can("enervate")
Truth table66%2/3
A and B
A= $has_warpB= $NCC::WarpCores{$module}->can("enervate")
ABresult
0X0
100
111
92 2 $WarpCores{$module}->enervate($module);
93 }
94 }
95  
96 3 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
97 3 ▶ *CORE::GLOBAL::require = sub { install_warpcore(@_) };
Subroutine __ANON__: called CC=1 SCAR=0.0
98 }
99  
100 3 1;
101  
102 __END__
↑ Summary NCC/WarpCore.pm »