blib/lib/Poet/Script.pm

filter: Statementstmt 91.5% 76 / 83 Branchbran 50.0% 12 / 24 Conditioncond 33.3% 4 / 12 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 94.7% 18 / 19 Podpod n/a totaltotal 75.3% 110 / 146 CC 17 SCAR 10.9
CC
17
Cov
77%
__ANON__
5.1
determine_root_dir
5.1
__ANON__
4.4
CRAP 3.0
« blib/lib/Poet/t/PSGIHandler.pm ↑ Summary blib/lib/Poet/t/Environment.pm »
1 package Poet::Script;
2 2 $Poet::Script::VERSION = '0.16';
3 4 ▶use Cwd qw(realpath);
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use File::Spec::Functions qw(rel2abs);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use Method::Signatures::Simple;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use Poet::Environment;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 ▶use Poet::Tools qw(can_load dirname read_file);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 4 ▶method import ($pkg:) {
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine import: called CC=2 SCAR=6.9
Subroutine __ANON__: called CC=2 SCAR=6.9
12 4 ▶ unless ( Poet::Environment->current_env ) {
Branch: 2 branches
BranchTrueFalseTotal
unless ("Poet::Environment"->current_env) 3 1 4
unless ("Poet::Environment"->current_env) 0 13 13
13 3 my $root_dir = determine_root_dir();
14 3 my $poet = initialize_with_root_dir($root_dir);
15 }
16 4 Poet::Environment->current_env->importer->export_to_level( 1, @_ );
17 2 }
18  
19 4 ▶func initialize_with_root_dir ($root_dir) {
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine initialize_with_root_dir: called CC=2 SCAR=7.5
Subroutine __ANON__: not called CC=2 SCAR=7.5
20 3 ▶ my ($app_name) = ( read_file("$root_dir/.poet_root") =~ /app_name: (.*)/ )
Branch: 2 branches
BranchTrueFalseTotal
my($app_name) = read_file("$root_dir/.poet_root") =~ /app_name: (.*)/ or die "cannot find app_name in $root_dir/.poet_root" 3 0 3
my($app_name) = read_file("$root_dir/.poet_root") =~ /app_name: (.*)/ or die "cannot find app_name in $root_dir/.poet_root" 0 0 0
21 or die "cannot find app_name in $root_dir/.poet_root";
22  
23 0 return Poet::Environment->initialize_current_environment(
24 root_dir => $root_dir,
25 app_name => $app_name
26 );
27 2 }
28  
29 4 ▶func determine_root_dir () {
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=4 SCAR=16.4
Subroutine determine_root_dir: called CC=4 SCAR=16.4
30  
31 # Search for .poet_root upwards from current directory, using rel2abs
32 # first, then realpath.
33 #
34 2 my $path1 = dirname( rel2abs($0) );
35 2 my $path2 = dirname( realpath($0) );
36 2 ▶ my $root_dir = search_upward($path1) || search_upward($path2);
Condition33%2/6
search_upward($path1) || search_upward($path2)
l!l&&r!l&&!r
200
search_upward($path1) || search_upward($path2)
l!l&&r!l&&!r
100
MC/DC0%0/2
search_upward($path1) || search_upward($path2)
search_upward($path1) search_upward($path2)
MC/DC0%0/2
search_upward($path1) || search_upward($path2)
search_upward($path1) search_upward($path2)
Truth table33%1/3
A || B
A= search_upward($path1)B= search_upward($path2)
ABresult
1X1
011
000
Truth table33%1/3
A || B
A= search_upward($path1)B= search_upward($path2)
ABresult
1X1
011
000
37 2 ▶ unless ( defined $root_dir ) {
Branch: 2 branches
BranchTrueFalseTotal
unless (defined $root_dir) 0 2 2
unless (defined $root_dir) 0 1 1
38 0 ▶ die sprintf( "could not find .poet_root upwards from %s",
Branch: 2 branches
BranchTrueFalseTotal
$path1 eq $path2 ? : 0 0 0
$path1 eq $path2 ? : 0 0 0
39 ( $path1 eq $path2 ) ? "'$path1'" : "'$path1' or '$path2'" );
40 }
41 2 return $root_dir;
42 2 }
43  
44 4 ▶func search_upward ($path) {
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine search_upward: called CC=4 SCAR=14.9
Subroutine __ANON__: called CC=4 SCAR=14.9
45 2 my $count = 0;
46 2 ▶ while ( realpath($path) ne '/' && $count++ < 10 ) {
Branch: 2 branches
BranchTrueFalseTotal
if (realpath($path) ne "/" and $count++ < 10) 6 0 6
if (realpath($path) ne "/" and $count++ < 10) 2 0 2
Condition33%2/6
realpath($path) ne "/" and $count++ < 10
!ll&&!rl&&r
006
realpath($path) ne "/" and $count++ < 10
!ll&&!rl&&r
002
MC/DC0%0/2
realpath($path) ne "/" and $count++ < 10
realpath($path) ne "/" $count++ < 10
MC/DC0%0/2
realpath($path) ne "/" and $count++ < 10
realpath($path) ne "/" $count++ < 10
Truth table33%1/3
A and B
A= realpath($path) ne "/"B= $count++ < 10
ABresult
0X0
100
111
Truth table33%1/3
A and B
A= realpath($path) ne "/"B= $count++ < 10
ABresult
0X0
100
111
47 6 ▶ if ( -f "$path/.poet_root" ) {
Branch: 2 branches
BranchTrueFalseTotal
if (-f "$path/.poet_root") 2 4 6
if (-f "$path/.poet_root") 1 1 2
48 2 return realpath($path);
49 0 last;
50 }
51 4 $path = dirname($path);
52 }
53 0 return undef;
54 2 }
55  
56 2 1;
57  
58 __END__
« blib/lib/Poet/t/PSGIHandler.pm ↑ Summary blib/lib/Poet/t/Environment.pm »