| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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)
search_upward($path1) || search_upward($path2)
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)
Truth table33%1/3
A || B
A= search_upward($path1)B= search_upward($path2)
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 2 | ▶ | unless ( defined $root_dir ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | ▶ | die sprintf( "could not find .poet_root upwards from %s", | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%2/6
realpath($path) ne "/" and $count++ < 10
realpath($path) ne "/" and $count++ < 10
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
Truth table33%1/3
A and B
A= realpath($path) ne "/"B= $count++ < 10
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 6 | ▶ | if ( -f "$path/.poet_root" ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||||||||||||||||||||||||