| 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
| |||||||||||||||||||||||||||||
| 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
Condition66%2/3
scalar @args == 1 and $args[0] eq "import"
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"
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 39 | 3 | ▶ | my $warpcore_class = scalar @args == 2 && $args[0] eq 'WarpCore' | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
scalar @args == 2 and $args[0] eq "WarpCore"
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"
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 43 | 3 | ▶ | croak "WarpCore needs at least an energize function" unless $warpcore_class->can('energize'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
Condition100%3/3
defined $files{$file} or not $file =~ /\.pm$/
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$/
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
Condition66%2/3
$has_warp and $NCC::WarpCores{$module}->can("enervate")
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")
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||