blib/lib/Poet/Environment/Generator.pm

filter: Statementstmt 100% 94 / 94 Branchbran 62.5% 20 / 32 Conditioncond 36.3% 8 / 22 MC/DCmcdc 0.0% 0 / 14 Subroutinesub 100% 13 / 13 Podpod n/a totaltotal 77.1% 135 / 175 CC 27 SCAR 23.3
CC
27
Cov
82%
__ANON__
14.7
generate_environment_directory
14.7
__ANON__
2.1
CRAP 10.2
↑ Summary blib/lib/Poet/Log.pm »
1 package Poet::Environment::Generator;
2 9 $Poet::Environment::Generator::VERSION = '0.16';
3 9 ▶use Cwd qw(realpath);
Subroutine BEGIN: called CC=1 SCAR=0.0
4 9 ▶use File::Find;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 9 ▶use File::ShareDir;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 9 ▶use Mason;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 9 ▶use Method::Signatures::Simple;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 9 ▶use Poet::Tools qw(basename dirname mkpath read_dir trim write_file);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 9 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 9 ▶method generate_environment_directory ($class: %params) {
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine generate_environment_directory: called CC=13 SCAR=26.9
Subroutine __ANON__: called CC=13 SCAR=26.9
13 14 ▶ my $root_dir = $params{root_dir} or die "must specify root_dir";
Branch: 2 branches
BranchTrueFalseTotal
my $root_dir = $params{"root_dir"} or die "must specify root_dir" 14 0 14
my $root_dir = $params{"root_dir"} or die "must specify root_dir" 4 0 4
14 14 ▶ my $app_name = $params{app_name} || basename($root_dir);
Condition33%2/6
$params{'app_name'} || basename($root_dir)
l!l&&r!l&&!r
1400
$params{'app_name'} || basename($root_dir)
l!l&&r!l&&!r
400
MC/DC0%0/2
$params{'app_name'} || basename($root_dir)
$params{'app_name'} basename($root_dir)
MC/DC0%0/2
$params{'app_name'} || basename($root_dir)
$params{'app_name'} basename($root_dir)
Truth table33%1/3
A || B
A= $params{'app_name'}B= basename($root_dir)
ABresult
1X1
011
000
Truth table33%1/3
A || B
A= $params{'app_name'}B= basename($root_dir)
ABresult
1X1
011
000
15 14 my $quiet = $params{quiet};
16 14 ▶ my $style = $params{style} || 'standard';
Condition50%2/4
$params{'style'} || 'standard'
l!l
140
$params{'style'} || 'standard'
l!l
40
MC/DC0%0/1
$params{'style'} || 'standard'
$params{'style'}
MC/DC0%0/1
$params{'style'} || 'standard'
$params{'style'}
Truth table50%1/2
A
A= $params{'style'}
Aresult
11
00
Truth table50%1/2
A
A= $params{'style'}
Aresult
11
00
17 577 ▶ my $msg = sub {
Subroutine __ANON__: called CC=2 SCAR=7.6
18 577 ▶ print "$_[0]\n" unless $quiet;
Branch: 1 branch
BranchTrueFalseTotal
unless $quiet 0 577 577
19 14 };
20  
21 14 ▶ die "invalid app_name '$app_name' - must be a valid Perl identifier"
Branch: 2 branches
BranchTrueFalseTotal
unless $app_name =~ qr/[[:alpha:]_]\w*/ 0 14 14
unless $app_name =~ qr/[[:alpha:]_]\w*/ 0 4 4
22 unless $app_name =~ qr/[[:alpha:]_]\w*/;
23 die "cannot generate environment in $root_dir - directory exists and is non-empty"
24 14 ▶ if ( -d $root_dir && @{ read_dir($root_dir) } );
Branch: 2 branches
BranchTrueFalseTotal
if -d $root_dir and @{read_dir($root_dir);} 0 14 14
if -d $root_dir and @{read_dir($root_dir);} 0 4 4
Condition33%2/6
-d $root_dir and @{read_dir($root_dir);}
!ll&&!rl&&r
0140
-d $root_dir and @{read_dir($root_dir);}
!ll&&!rl&&r
040
MC/DC0%0/2
-d $root_dir and @{read_dir($root_dir);}
-d $root_dir @{read_dir($root_dir);}
MC/DC0%0/2
-d $root_dir and @{read_dir($root_dir);}
-d $root_dir @{read_dir($root_dir);}
Truth table33%1/3
A and B
A= -d $root_dirB= @{read_dir($root_dir);}
ABresult
0X0
100
111
Truth table33%1/3
A and B
A= -d $root_dirB= @{read_dir($root_dir);}
ABresult
0X0
100
111
25  
26 14 ▶ my $share_dir = realpath( $ENV{POET_SHARE_DIR} || File::ShareDir::dist_dir('Poet') );
Condition33%2/6
$ENV{'POET_SHARE_DIR'} || File::ShareDir::dist_dir('Poet')
l!l&&r!l&&!r
1400
$ENV{'POET_SHARE_DIR'} || File::ShareDir::dist_dir('Poet')
l!l&&r!l&&!r
400
MC/DC0%0/2
$ENV{'POET_SHARE_DIR'} || File::ShareDir::dist_dir('Poet')
$ENV{'POET_SHARE_DIR'} File::ShareDir::dist_dir('Poet')
MC/DC0%0/2
$ENV{'POET_SHARE_DIR'} || File::ShareDir::dist_dir('Poet')
$ENV{'POET_SHARE_DIR'} File::ShareDir::dist_dir('Poet')
Truth table33%1/3
A || B
A= $ENV{'POET_SHARE_DIR'}B= File::ShareDir::dist_dir('Poet')
ABresult
1X1
011
000
Truth table33%1/3
A || B
A= $ENV{'POET_SHARE_DIR'}B= File::ShareDir::dist_dir('Poet')
ABresult
1X1
011
000
27 14 ▶ die "cannot find Poet share dir '$share_dir'" unless -d $share_dir;
Branch: 2 branches
BranchTrueFalseTotal
unless -d $share_dir 0 14 14
unless -d $share_dir 0 4 4
28 14 my $comp_root = "$share_dir/generate.skel";
29 14 my $interp = Mason->new(
30 comp_root => $comp_root,
31 autoextend_request_path => 0,
32 top_level_regex => qr/./,
33 allow_globals => [qw($app_name $root_dir)],
34 );
35 14 $interp->set_global( '$app_name' => $app_name );
36 14 $interp->set_global( '$root_dir' => $root_dir );
37  
38 14 ▶ my @paths = $interp->all_paths()
Branch: 2 branches
BranchTrueFalseTotal
my(@paths) = $interp->all_paths or die "could not find template components" 14 0 14
my(@paths) = $interp->all_paths or die "could not find template components" 4 0 4
39 or die "could not find template components";
40  
41 14 foreach my $path (@paths) {
42 437 ▶ next if $path =~ m{/\.}; # .svn, .git, etc.
Branch: 2 branches
BranchTrueFalseTotal
if $path =~ m[/\.] 2 435 437
if $path =~ m[/\.] 0 124 124
43 435 my $output = trim( $interp->run($path)->output );
44 435 ( my $dest = $path ) =~ s{/DOT_}{/.}g;
45 435 $dest = $root_dir . $dest;
46 435 $dest =~ s|$root_dir/lib/MyApp|$root_dir/lib/$app_name|;
47 435 mkpath( dirname($dest), 0, 0775 );
48 435 ▶ if ( $path =~ /EMPTY$/ ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($path =~ /EMPTY$/) { } 112 323 435
if ($path =~ /EMPTY$/) { } 32 92 124
49 112 $msg->( dirname($dest) );
50 }
51 else {
52 323 $msg->($dest);
53 323 write_file( $dest, $output );
54 }
55 }
56  
57 14 ▶ find( sub { chmod( 0775, $_ ) if /\.pl$/ }, $root_dir );
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if /\.pl$/ 54 722 776
58 14 $msg->("\nNow run '$root_dir/bin/run.pl' to start your server.");
59  
60 14 return $root_dir;
61 9 }
62  
63 9 1;
↑ Summary blib/lib/Poet/Log.pm »