| 1 | package autorequire ; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use strict ; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use Carp ; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use File::Spec ; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use IO::File ; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | 3 | our $VERSION = '0.08' ; | |||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | 10 | ▶ | sub import { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
import: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 10 | my $class = shift ; | |||||||||||||||||||||||||||||||||||||||||
| 14 | 10 | my $sub = shift ; | |||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | 10 | my $ar = $class->new($sub) ; | |||||||||||||||||||||||||||||||||||||||||
| 17 | 10 | ▶ | $ar->insert(-1) if defined($sub) ; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | } | ||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | 13 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | 13 | my $class = shift ; | |||||||||||||||||||||||||||||||||||||||||
| 23 | 13 | my $sub = shift ; | |||||||||||||||||||||||||||||||||||||||||
| 24 | 13 | ▶ | my $list = shift || \@INC ; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
shift() || \@INC
MC/DC100%1/1
shift() || \@INC
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | 13 | my $this = {} ; | |||||||||||||||||||||||||||||||||||||||||
| 27 | 13 | $this->{'sub'} = $sub ; | |||||||||||||||||||||||||||||||||||||||||
| 28 | 13 | $this->{'list'} = $list ; | |||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | 13 | bless($this, $class) ; | |||||||||||||||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | 44 | ▶ | sub _get_sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_sub: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | 44 | my $this = shift ; | |||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | 44 | return $this->{'sub'} ; | |||||||||||||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | 8 | ▶ | sub _get_list { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_list: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | 8 | my $this = shift ; | |||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | 8 | return $this->{'list'} ; | |||||||||||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||
| 48 | # Insert $this into @INC at the specified | ||||||||||||||||||||||||||||||||||||||||||
| 49 | # position. | ||||||||||||||||||||||||||||||||||||||||||
| 50 | 8 | ▶ | sub insert { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
insert: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | 8 | my $this = shift ; | |||||||||||||||||||||||||||||||||||||||||
| 52 | 8 | my $idx = shift ; | |||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | 8 | my $l = $this->_get_list() ; | |||||||||||||||||||||||||||||||||||||||||
| 55 | 8 | ▶ | if (! scalar(@{$l})){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | 2 | push @{$l}, $this ; | |||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||
| 58 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 59 | 6 | my $cur = $l->[$idx] ; | |||||||||||||||||||||||||||||||||||||||||
| 60 | 6 | ▶ | splice(@{$l}, $idx, 1, | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | ($idx >= 0 | ||||||||||||||||||||||||||||||||||||||||||
| 62 | 6 | ? (scalar(@{$l}) > $idx | |||||||||||||||||||||||||||||||||||||||||
| 63 | ? ($this, $cur) | ||||||||||||||||||||||||||||||||||||||||||
| 64 | : ($this)) | ||||||||||||||||||||||||||||||||||||||||||
| 65 | : ($cur, $this))) ; | ||||||||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||
| 70 | # Remove $this from the @INC array. | ||||||||||||||||||||||||||||||||||||||||||
| 71 | 2 | ▶ | sub delete { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
delete: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 72 | 2 | my $this = shift ; | |||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | 2 | ▶ | for (my $i = 0 ; $i < scalar(@{$this->{'list'}}) ; $i++){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | 23 | ▶ | if ($INC[$i] eq $this){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | 2 | splice(@{$this->{'list'}}, $i, 1) ; | |||||||||||||||||||||||||||||||||||||||||
| 77 | 2 | $i-- ; | |||||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||
| 83 | 2 | ▶ | sub enable { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
enable: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | 2 | my $this = shift ; | |||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||
| 86 | 2 | $this->{disabled} = 0 ; | |||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||
| 90 | 3 | ▶ | sub disable { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
disable: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 91 | 3 | my $this = shift ; | |||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||
| 93 | 3 | $this->{disabled} = 1 ; | |||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||
| 97 | 45 | ▶ | sub autorequire::INC { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
INC: called CC=11 SCAR=24.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 98 | 45 | my ($this, $f) = @_ ; | |||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | 45 | ▶ | return undef if $this->{disabled} ; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||
| 102 | 44 | my $s = $this->_get_sub() ; | |||||||||||||||||||||||||||||||||||||||||
| 103 | 44 | ▶ | if (! ref($s)){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 104 | # Symbolic reference. It may not be defined yet. | ||||||||||||||||||||||||||||||||||||||||||
| 105 | 4 | ▶ | return undef if !defined(&{$s}) ; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 106 | 3 | $s = \&{$s} ; | |||||||||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||
| 109 | 43 | my $ret = $s->($this, $f) ; | |||||||||||||||||||||||||||||||||||||||||
| 110 | 43 | ▶ | if (defined($ret)){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 111 | 5 | ▶ | if (! _is_handle($ret)){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 112 | # Maybe the value returned is the name of a file. | ||||||||||||||||||||||||||||||||||||||||||
| 113 | 4 | ▶ | if (($ret !~ /\n/)&&(-r $ret)){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not $ret =~ /\n/ and -r $ret
MC/DC100%2/2
not $ret =~ /\n/ and -r $ret
not $ret =~ /\n/
-r $ret
Truth table100%3/3
not(A) and B
A= not $ret =~ /\n/B= -r $ret
| |||||||||||||||||||||||||||||||||||||||||||
| 114 | 1 | my $file = $ret ; | |||||||||||||||||||||||||||||||||||||||||
| 115 | 1 | $ret = undef ; | |||||||||||||||||||||||||||||||||||||||||
| 116 | 1 | ▶ | open($ret, "<$file") or | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 117 | croak("Can't open '$file' for reading: $!") ; | ||||||||||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||||||||
| 119 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 120 | 3 | my $code = $ret ; | |||||||||||||||||||||||||||||||||||||||||
| 121 | 3 | $ret = undef ; | |||||||||||||||||||||||||||||||||||||||||
| 122 | 3 | ▶ | open($ret, '<', (ref($code) ? $code : \$code)) or | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 123 | croak("Can't open in-memory filehandle: $!") ; | ||||||||||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||
| 128 | 43 | return $ret ; | |||||||||||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||
| 132 | # Pasted from File::Copy | ||||||||||||||||||||||||||||||||||||||||||
| 133 | 5 | ▶ | sub _is_handle { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_is_handle: called CC=4 SCAR=14.2
| |||||||||||||||||||||||||||||||||||||||||||
| 134 | 5 | my $h = shift ; | |||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||
| 136 | 5 | ▶ | return (ref($h) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
ref $h eq "GLOB" or UNIVERSAL::isa($h, "GLOB") or UNIVERSAL::isa($h, "IO::Handle")
ref $h eq "GLOB" or UNIVERSAL::isa($h, "GLOB")
MC/DC33%1/3
ref $h eq "GLOB" or UNIVERSAL::isa($h, "GLOB") or UNIVERSAL::isa($h, "IO::Handle")
ref $h eq "GLOB"
UNIVERSAL::isa($h, "GLOB")
UNIVERSAL::isa($h, "IO::Handle")
Truth table50%2/4
A or B or C
A= ref $h eq "GLOB"B= UNIVERSAL::isa($h, "GLOB")C= UNIVERSAL::isa($h, "IO::Handle")
| |||||||||||||||||||||||||||||||||||||||||||
| 137 | ? (ref($h) eq 'GLOB' | ||||||||||||||||||||||||||||||||||||||||||
| 138 | || UNIVERSAL::isa($h, 'GLOB') | ||||||||||||||||||||||||||||||||||||||||||
| 139 | || UNIVERSAL::isa($h, 'IO::Handle')) | ||||||||||||||||||||||||||||||||||||||||||
| 140 | : (ref(\$h) eq 'GLOB')) ; | ||||||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||
| 144 | 4 | ▶ | sub is_loaded { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_loaded: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 145 | 4 | my $class = shift ; | |||||||||||||||||||||||||||||||||||||||||
| 146 | 4 | my $filename = shift ; | |||||||||||||||||||||||||||||||||||||||||
| 147 | 4 | my %opts = @_ ; | |||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||
| 149 | 4 | my $I = $INC{$filename} ; | |||||||||||||||||||||||||||||||||||||||||
| 150 | 4 | return $class->_name_or_open_or_slurp_file($I, %opts) ; | |||||||||||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||
| 154 | 2 | ▶ | sub is_installed { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_installed: called CC=5 SCAR=16.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 155 | 2 | my $class = shift ; | |||||||||||||||||||||||||||||||||||||||||
| 156 | 2 | my $filename = shift ; | |||||||||||||||||||||||||||||||||||||||||
| 157 | 2 | my %opts = @_ ; | |||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||
| 159 | 2 | my $file = undef ; | |||||||||||||||||||||||||||||||||||||||||
| 160 | 2 | ▶ | if (File::Spec->file_name_is_absolute($filename)){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 161 | 0 | $file = $filename ; | |||||||||||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||||||||||||
| 163 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 164 | 2 | foreach my $I (@INC){ | |||||||||||||||||||||||||||||||||||||||||
| 165 | 17 | ▶ | next if ref($I) ; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 166 | 15 | my $test = File::Spec->catfile($I, $filename) ; | |||||||||||||||||||||||||||||||||||||||||
| 167 | 15 | ▶ | if (-r File::Spec->catfile($I, $filename)){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 168 | 1 | $file = $test ; | |||||||||||||||||||||||||||||||||||||||||
| 169 | 1 | last ; | |||||||||||||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||
| 174 | 2 | return $class->_name_or_open_or_slurp_file($file, %opts) ; | |||||||||||||||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||
| 178 | 11 | ▶ | sub _name_or_open_or_slurp_file { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_name_or_open_or_slurp_file: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 179 | 11 | my $class = shift ; | |||||||||||||||||||||||||||||||||||||||||
| 180 | 11 | my $file = shift ; | |||||||||||||||||||||||||||||||||||||||||
| 181 | 11 | my %opts = @_ ; | |||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||
| 183 | 11 | ▶ | return undef unless defined($file) ; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||
| 185 | 7 | ▶ | if (($opts{'open'})||($opts{slurp})){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$opts{"open"} or $opts{"slurp"}
MC/DC100%2/2
$opts{"open"} or $opts{"slurp"}
$opts{"open"}
$opts{"slurp"}
Truth table100%3/3
A or B
A= $opts{"open"}B= $opts{"slurp"}
| |||||||||||||||||||||||||||||||||||||||||||
| 186 | 3 | my $fh = new IO::File("<$file") ; | |||||||||||||||||||||||||||||||||||||||||
| 187 | 3 | ▶ | croak("Can't open '$file' for reading: $!") unless defined($fh) ; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||
| 189 | 3 | ▶ | if ($opts{slurp}){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 190 | 1 | local $/ = undef ; | |||||||||||||||||||||||||||||||||||||||||
| 191 | 1 | return <$fh> ; | |||||||||||||||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||
| 194 | 2 | return $fh ; | |||||||||||||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||||
| 197 | 4 | return $file ; | |||||||||||||||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||
| 201 | 3 | 1 ; | |||||||||||||||||||||||||||||||||||||||||
| 202 | __END__ | ||||||||||||||||||||||||||||||||||||||||||