blib/lib/perl5i/2.pm

filter: Statementstmt 98.4% 123 / 125 Branchbran 80.0% 16 / 20 Conditioncond 75.0% 6 / 8 MC/DCmcdc 60.0% 3 / 5 Subroutinesub 100% 38 / 38 Podpod 0.0% 0 / 5 totaltotal 92.5% 186 / 201 SCAR 28.4
CC
17
Cov
95%
import
7.0
perl5i_die
4.0
__ANON__
3.2
CRAP 17.0
« blib/lib/perl5i/0/HASH.pm ↑ Summary blib/lib/perl5i/1.pm »
1 # vi: set ts=4 sw=4 ht=4 et :
2 package perl5i::2;
3  
4 109 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 109 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 109 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 #This should come first
10 109 ▶use perl5i::2::RequireMessage;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 109 ▶use Carp::Fix::1_25;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 109 ▶use perl5i::2::autobox;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 109 ▶use Import::Into;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 109 ▶use perl5i::VERSION; our $VERSION = perl5i::VERSION->VERSION;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 109 our $Latest = perl5i::VERSION->latest;
19  
20 my %Features = (
21 # A stub for autodie. It's handled specially in import().
22 ▶ autodie => sub {},
Subroutine __ANON__: called CC=1 SCAR=0.0
23 autobox => sub {
24 115 ▶ my ($class, $caller) = @_;
Subroutine __ANON__: called CC=1 SCAR=0.0
25 115 perl5i::2::autobox->import::into($caller);
26 },
27 autovivification => sub {
28 115 ▶ my ($class, $caller) = @_;
Subroutine __ANON__: called CC=1 SCAR=0.0
29 115 autovivification->unimport::out_of($caller);
30 },
31 capture => sub {
32 115 ▶ my ($class, $caller) = @_;
Subroutine __ANON__: called CC=1 SCAR=0.0
33 115 (\&capture)->alias($caller, "capture");
34 },
35 "Carp::Fix::1_25" => sub {
36 115 ▶ my ($class, $caller) = @_;
Subroutine __ANON__: called CC=1 SCAR=0.0
37 115 Carp::Fix::1_25->import::into($caller);
38 },
39 Child => sub {
40 115 ▶ my ($class, $caller) = @_;
Subroutine __ANON__: called CC=1 SCAR=0.0
41 115 Child->import::into( $caller => qw(child) );
42 },
43 CLASS => sub {
44 115 ▶ my ($class, $caller) = @_;
Subroutine __ANON__: called CC=1 SCAR=0.0
45 115 CLASS->import::into( $caller );
46 },
47 die => sub {
48 115 ▶ my ($class, $caller) = @_;
Subroutine __ANON__: called CC=1 SCAR=0.0
49 115 (\&perl5i_die)->alias($caller, "die");
50 },
51 English => sub {
52 115 ▶ my ($class, $caller) = @_;
Subroutine __ANON__: called CC=1 SCAR=0.0
53 115 English->import::into( $caller => qw(-no_match_vars) );
54 },
55 'File::chdir' => sub {
56 115 ▶ my ($class, $caller) = @_;
Subroutine __ANON__: called CC=1 SCAR=0.0
57 115 File::chdir->import::into( $caller );
58 },
59 indirect => sub {
60 115 ▶ my ($class, $caller) = @_;
Subroutine __ANON__: called CC=1 SCAR=0.0
61 115 indirect->unimport::out_of($caller, ":fatal");
62 },
63 list => sub {
64 115 ▶ my ($class, $caller) = @_;
Subroutine __ANON__: called CC=1 SCAR=0.0
65 115 (\&force_list_context)->alias($caller, 'list');
66 },
67 Meta => sub {
68 115 ▶ require perl5i::2::Meta;
Subroutine __ANON__: called CC=1 SCAR=0.0
69 },
70 'Modern::Perl' => sub {
71 115 ▶ my ($class, $caller) = @_;
Subroutine __ANON__: called CC=3 SCAR=11.8
72  
73 # use Modern::Perl
74 115 Modern::Perl->import::into($caller);
75  
76 # no strict vars for oneliners - GH #63
77 115 ▶ strict::unimport($class, 'vars')
Branch: 1 branch
BranchTrueFalseTotal
if $class eq "perl5i::cmd" or $0 eq "-e" 0 115 115
Condition33%1/3
$class eq "perl5i::cmd" or $0 eq "-e"
l!l&&r!l&&!r
00115
MC/DC0%0/2
$class eq "perl5i::cmd" or $0 eq "-e"
$class eq "perl5i::cmd" $0 eq "-e"
Truth table33%1/3
A or B
A= $class eq "perl5i::cmd"B= $0 eq "-e"
ABresult
1X1
011
000
78 if $class eq 'perl5i::cmd'
79 or $0 eq '-e';
80  
81 # Modern::Perl won't pass this through to our caller.
82 115 require mro;
83 115 mro::set_mro($caller, 'c3');
84 },
85 'Perl6::Caller' => sub {
86 115 ▶ my ($class, $caller) = @_;
Subroutine __ANON__: called CC=1 SCAR=0.0
87 115 Perl6::Caller->import::into($caller);
88 },
89 Signatures => sub {
90 114 ▶ my ($class, $caller) = @_;
Subroutine __ANON__: called CC=1 SCAR=0.0
91 114 perl5i::2::Signatures->import::into($caller);
92 },
93 stat => sub {
94 115 ▶ my ($class, $caller) = @_;
Subroutine __ANON__: called CC=1 SCAR=0.0
95  
96 115 require File::stat;
97 # Export our stat and lstat
98 115 (\&stat)->alias($caller, 'stat');
99 115 (\&lstat)->alias($caller, 'lstat');
100 },
101 time => sub {
102 115 ▶ my ($class, $caller) = @_;
Subroutine __ANON__: called CC=1 SCAR=0.0
103  
104 115 require perl5i::2::DateTime;
105 # Export our gmtime() and localtime()
106 115 (\&perl5i::2::DateTime::dt_gmtime)->alias($caller, 'gmtime');
107 115 (\&perl5i::2::DateTime::dt_localtime)->alias($caller, 'localtime');
108 115 (\&perl5i::2::DateTime::dt_time)->alias($caller, 'time');
109 },
110 true => sub {
111 115 ▶ my ($class, $caller) = @_;
Subroutine __ANON__: called CC=1 SCAR=0.0
112 115 true->import::into($caller);
113 },
114 'Try::Tiny' => sub {
115 115 ▶ my ($class, $caller) = @_;
Subroutine __ANON__: called CC=1 SCAR=0.0
116 115 Try::Tiny->import::into($caller);
117 },
118 'utf8::all' => sub {
119 115 ▶ my ($class, $caller) = @_;
Subroutine __ANON__: called CC=2 SCAR=7.1
120 115 utf8::all->import::into($caller);
121 115 ▶ "feature"->unimport::out_of($caller, "unicode_eval") if $^V >= v5.16.0;
Branch: 1 branch
BranchTrueFalseTotal
if $^V >= v5.16.0 115 0 115
122 },
123 Want => sub {
124 115 ▶ my ($class, $caller) = @_;
Subroutine __ANON__: called CC=1 SCAR=0.0
125 115 Want->import::into( $caller => qw(want) );
126 },
127 109 );
128  
129 # This is necessary for autodie to work and be lexical
130 109 ▶use parent 'autodie';
Subroutine BEGIN: called CC=1 SCAR=0.0
131  
132 ## no critic (Subroutines::RequireArgUnpacking)
133 sub import {
134 117 ▶ my $class = shift;
Subroutine import: called CC=7 SCAR=19.5
135 117 my %import = @_;
136  
137 117 my $caller = caller;
138  
139 # Read the skip list and turn it into a hash
140 117 ▶ my $skips = delete $import{-skip} || [];
Condition100%2/2
delete $import{'-skip'} || []
l!l
3114
MC/DC100%1/1
delete $import{'-skip'} || []
delete $import{'-skip'}
Truth table100%2/2
A
A= delete $import{'-skip'}
Aresult
11
00
141 117 $skips = { map { $_ => 1 } @$skips };
142  
143 # Any remaining import parameters are unknown
144 117 ▶ if( keys %import ) {
Branch: 1 branch
BranchTrueFalseTotal
if (keys %import) 1 116 117
145 croak sprintf "Unknown parameters '%s' in import list",
146 1 join(", ", map { "$_ => $import{$_}" } keys %import);
147 }
148  
149 # Check all the skipped features are valid
150 116 for my $f ( grep { !exists $Features{$_} } keys %$skips ) {
151 1 croak "Unknown feature '$f' in skip list";
152 }
153  
154 # Current lexically active major version of perl5i.
155 115 $^H{perl5i} = 2;
156  
157 # Load all the features.
158 115 for my $feature (keys %Features) {
159 2530 ▶ next if $skips->{$feature};
Branch: 1 branch
BranchTrueFalseTotal
if $skips->{$feature} 2 2528 2530
160 2528 $Features{$feature}->($class, $caller);
161 }
162  
163 # autodie needs a bit more convincing
164 115 ▶ if( !$skips->{autodie} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $skips->{"autodie"}) 114 1 115
165 114 @_ = ( $class, ":all" );
166 114 goto &autodie::import;
167 }
168 }
169  
170 1 ▶sub unimport { $^H{perl5i} = 0 }
Subroutine unimport: called CC=1 SCAR=0.0
171  
172 # fix die so that it always returns 255
173 sub perl5i_die {
174 # Leave a single ref be
175 25 ▶ local $! = 255;
Subroutine perl5i_die: called CC=4 SCAR=13.9
Pod undocumented
176 25 ▶ return CORE::die(@_) if @_ == 1 and ref $_[0];
Branch: 1 branch
BranchTrueFalseTotal
if @_ == 1 and ref $_[0] 2 23 25
Condition100%3/3
@_ == 1 and ref $_[0]
!ll&&!rl&&r
1582
MC/DC100%2/2
@_ == 1 and ref $_[0]
@_ == 1 ref $_[0]
Truth table100%3/3
A and B
A= @_ == 1B= ref $_[0]
ABresult
0X0
100
111
177  
178 23 my $error = join '', @_;
179 23 ▶ unless ($error =~ /\n$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($error =~ /\n$/) 16 7 23
180 16 my ($file, $line) = (caller)[1,2];
181 16 $error .= " at $file line $line.\n";
182 }
183  
184 23 local $! = 255;
185 23 return CORE::die($error);
186 }
187  
188  
189 # File::stat does not play nice in list context
190 sub stat {
191 3 ▶ return CORE::stat(@_) if wantarray;
Subroutine stat: called CC=2 SCAR=6.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
if wantarray 1 2 3
192 2 return File::stat::stat(@_);
193 }
194  
195 sub lstat {
196 1 ▶ return CORE::lstat(@_) if wantarray;
Subroutine lstat: called CC=2 SCAR=9.2
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
if wantarray 1 0 1
197 0 return File::stat::lstat(@_);
198 }
199  
200  
201 sub capture(&;@) {
202 16 ▶ my($code, %opts) = @_;
Subroutine capture: called CC=3 SCAR=11.1
Pod undocumented
203  
204 # valid options
205 16 state $valid_options = { map { $_ => 1 } qw(merge tee) };
206  
207 16 for my $key (keys %opts) {
208 2 ▶ croak "$key is not a valid option to capture()" unless $valid_options->{$key};
Branch: 1 branch
BranchTrueFalseTotal
unless $valid_options->{$key} 0 2 2
209 }
210  
211 16 my $opts = join "/", sort { $a cmp $b } grep { $opts{$_} } keys %opts;
212  
213 # Translate option combinations into Capture::Tiny functions
214 16 require Capture::Tiny;
215 16 state $captures = {
216 "" => \&Capture::Tiny::capture,
217 "tee" => \&Capture::Tiny::tee,
218 "merge" => \&Capture::Tiny::capture_merged,
219 "merge/tee" => \&Capture::Tiny::tee_merged
220 };
221  
222 16 my $func = $captures->{$opts};
223 16 return $func->($code);
224 }
225  
226  
227 sub force_list_context(@) {
228 6 ▶ return @_;
Subroutine force_list_context: called CC=1 SCAR=0.0
Pod undocumented
229 }
230  
231 109 1;
« blib/lib/perl5i/0/HASH.pm ↑ Summary blib/lib/perl5i/1.pm »