| 1 | |||||||||||||||||||||||||||||
| 2 | 13 | ▶ | use v5.10; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 13 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 13 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | package Test::Load::Helper v2.0.0; | ||||||||||||||||||||||||||||
| 7 | { | ||||||||||||||||||||||||||||
| 8 | 12 | ▶ | use Carp qw (croak); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 12 | ▶ | use Path::Tiny qw (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 12 | our $DEFAULT_FILENAME = q (test-helper.pl); | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 17 | ▶ | sub eval_helper { | ||||||||||||||||||||||||||
|
Subroutine
eval_helper: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 14 | 17 | my ($class, %args) = @_; | |||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 17 | my $key = $class->inc_key (%args); | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | return 1 | ||||||||||||||||||||||||||||
| 19 | 17 | ▶ | if exists $INC{$key} | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 20 | ; | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 15 | my $file = $args{file}; | |||||||||||||||||||||||||||
| 23 | 15 | my $code = $file->slurp_utf8; | |||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | { | ||||||||||||||||||||||||||||
| 26 | 12 | ▶ | no strict q (refs); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 27 | 10 | ▶ | eval <<"END_OF_EVAL"; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 28 | package $args{into}; | ||||||||||||||||||||||||||||
| 29 | use strict; | ||||||||||||||||||||||||||||
| 30 | use warnings; | ||||||||||||||||||||||||||||
| 31 | #line 1 "$file" | ||||||||||||||||||||||||||||
| 32 | $code; | ||||||||||||||||||||||||||||
| 33 | 1; | ||||||||||||||||||||||||||||
| 34 | END_OF_EVAL | ||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 15 | ▶ | croak qq (Test::Load::Helper: Error compiling '$file': $@) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 38 | if $@ | ||||||||||||||||||||||||||||
| 39 | ; | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 14 | $INC{$key} = "$file"; | |||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 14 | return 1; | |||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 19 | ▶ | sub identify_caller_file { | ||||||||||||||||||||||||||
|
Subroutine
identify_caller_file: called CC=4 SCAR=14.3
Pod
undocumented
| |||||||||||||||||||||||||||||
| 47 | 19 | my ($class, %args) = @_; | |||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 19 | my $level = 0; | |||||||||||||||||||||||||||
| 50 | 19 | ▶ | while (my @info = caller ($level++)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | 57 | my $file = $info[1]; | |||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | next | ||||||||||||||||||||||||||||
| 54 | 57 | ▶ | if $file eq __FILE__ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | ; | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 19 | ▶ | return Path::Tiny::->new ($file) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | if -f $file | ||||||||||||||||||||||||||||
| 59 | ; | ||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 0 | return; | |||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 19 | ▶ | sub identify_caller_package { | ||||||||||||||||||||||||||
|
Subroutine
identify_caller_package: called CC=4 SCAR=14.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 66 | 19 | my ($class, %args) = @_; | |||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | return $args{into} | ||||||||||||||||||||||||||||
| 69 | if exists $args{into} | ||||||||||||||||||||||||||||
| 70 | 19 | ▶ | ; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 18 | my $level = 0; | |||||||||||||||||||||||||||
| 73 | 18 | ▶ | while (my @info = caller ($level++)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 74 | 36 | my $package = $info[0]; | |||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | next | ||||||||||||||||||||||||||||
| 77 | 36 | ▶ | if $package eq __PACKAGE__ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 78 | ; | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 18 | return $package; | |||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 0 | return q (main); | |||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 19 | ▶ | sub identify_helper_file { | ||||||||||||||||||||||||||
|
Subroutine
identify_helper_file: called CC=9 SCAR=22.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 87 | 19 | my ($class, %args) = @_; | |||||||||||||||||||||||||||
| 88 | 19 | ▶ | my $file = $args{file} // $DEFAULT_FILENAME; | ||||||||||||||||||||||||||
|
Condition66%2/3
$args{"file"} // $Test::Load::Helper::DEFAULT_FILENAME
MC/DC0%0/2
$args{"file"} // $Test::Load::Helper::DEFAULT_FILENAME
$args{"file"}
$Test::Load::Helper::DEFAULT_FILENAME
Truth table66%2/3
A // B
A= $args{"file"}B= $Test::Load::Helper::DEFAULT_FILENAME
| |||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | return | ||||||||||||||||||||||||||||
| 91 | unless my $caller_file = exists $args{caller_file} | ||||||||||||||||||||||||||||
| 92 | ? Path::Tiny::->new ($args{caller_file}) | ||||||||||||||||||||||||||||
| 93 | 19 | ▶ | : $class->identify_caller_file (%args) | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 94 | ; | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 19 | my $caller_dir = $caller_file->parent->absolute; | |||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | my $root = $ENV{TEST_LOAD_ROOT} | ||||||||||||||||||||||||||||
| 99 | 19 | ▶ | ? Path::Tiny::->new ($ENV{TEST_LOAD_ROOT})->absolute | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 100 | : Path::Tiny::->new (q (/)) | ||||||||||||||||||||||||||||
| 101 | ; | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 19 | while (1) { | |||||||||||||||||||||||||||
| 104 | 30 | my $candidate = $caller_dir->child ($file); | |||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | 30 | ▶ | return $candidate | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$candidate ne $caller_file and $candidate->exists
MC/DC100%2/2
$candidate ne $caller_file and $candidate->exists
$candidate ne $caller_file
$candidate->exists
Truth table100%3/3
A and B
A= $candidate ne $caller_fileB= $candidate->exists
| |||||||||||||||||||||||||||||
| 107 | if $candidate ne $caller_file | ||||||||||||||||||||||||||||
| 108 | && $candidate->exists | ||||||||||||||||||||||||||||
| 109 | ; | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | last | ||||||||||||||||||||||||||||
| 112 | 13 | ▶ | if $caller_dir eq $root | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 113 | ; | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | 11 | my $parent = $caller_dir->parent; | |||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | last | ||||||||||||||||||||||||||||
| 118 | 11 | ▶ | if $parent eq $caller_dir | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 119 | ; | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | 11 | $caller_dir = $parent; | |||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | 2 | return; | |||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | 19 | ▶ | sub import { | ||||||||||||||||||||||||||
|
Subroutine
import: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 128 | 19 | my ($class, %args) = @_; | |||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | return | ||||||||||||||||||||||||||||
| 131 | 19 | ▶ | unless my $caller_package = $class->identify_caller_package (%args) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 132 | ; | ||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | 19 | ▶ | return 1 | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 135 | unless my $helper_file = $class->identify_helper_file (%args) | ||||||||||||||||||||||||||||
| 136 | ; | ||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | 17 | $class->eval_helper ( | |||||||||||||||||||||||||||
| 139 | into => $caller_package, | ||||||||||||||||||||||||||||
| 140 | file => $helper_file, | ||||||||||||||||||||||||||||
| 141 | ); | ||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | 17 | ▶ | sub inc_key { | ||||||||||||||||||||||||||
|
Subroutine
inc_key: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 145 | 17 | my ($class, %args) = @_; | |||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | 17 | my $into = $args{into}; | |||||||||||||||||||||||||||
| 148 | 17 | my $file = $args{file}; | |||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | # File can be loaded into multiple target packages | ||||||||||||||||||||||||||||
| 151 | 17 | qq (${file}{${into}}); | |||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | 12 | 1; | |||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | __END__ | ||||||||||||||||||||||||||||