Perlude/Open.pm

filter: Statementstmt 100% 24 / 24 Branchbran 66.6% 4 / 6 Conditioncond 33.3% 2 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 100% 8 / 8 Podpod 0.0% 0 / 1 totaltotal 77.5% 38 / 49 CC 6 SCAR 7.0
CC
6
Cov
83%
open_file
3.2
_callback_for_nargs
2.3
_source_for_nargs
2.0
CRAP 2.0
« Perlude.pm ↑ Summary Perlude/builtins.pm »
1 package Perlude::Open;
2 14 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 14 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 14 ▶use 5.10.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 14 ▶use Exporter qw< import >;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 14 our @EXPORT = qw< open_file >;
7  
8 4 ▶sub _source_for_nargs (_) {
Subroutine _source_for_nargs: called CC=2 SCAR=7.0
9 4 ▶ my $nargs = shift or die;
Branch: 1 branch
BranchTrueFalseTotal
my $nargs = shift() or die 4 0 4
10 4 my $args = join ',', map {'$a'.$_} 1..$nargs;
11 4 sprintf 'sub {
12 my (%s) = @_;
13 open my $fh, %s
14 or die "$! while open_file %s";
15 $fh; }', ($args)x3;
16 };
17  
18 1 ▶sub _prepare_special_forms {
Subroutine _prepare_special_forms: called CC=2 SCAR=7.0
19 +{ map {
20 1 my $cb = eval _source_for_nargs;
21 4 ▶ $@ and die $@;
Branch: 1 branch
BranchTrueFalseTotal
$@ and die $@ 0 4 4
22 4 $_ => $cb; } 1..4 };
23 }
24  
25 2 ▶sub _callback_for_nargs(_) {
Subroutine _callback_for_nargs: called CC=2 SCAR=8.1
26 # build callbacks for number of arguments from 1 to 4
27 2 state $open_with = _prepare_special_forms;
28 # the 4 arguments form callback should work for 4 and more.
29 # i copy this ref on demand whenever i see a new number of arguments
30 2 ▶ $open_with->{ +@_ } ||= $open_with->{4};
Condition33%1/3
$$open_with{@_} ||= $open_with->{4}
l!l&&r!l&&!r
200
MC/DC0%0/2
$$open_with{@_} ||= $open_with->{4}
$$open_with{@_} $open_with->{4}
Truth table33%1/3
A ||= B
A= $$open_with{@_}B= $open_with->{4}
ABresult
1X1
011
000
31 }
32  
33 5 ▶sub open_file {
Subroutine open_file: called CC=3 SCAR=11.7
Pod undocumented
34 # if the file (can be $_) is open, just return
35 5 ▶ return shift if ref ($_[0]||=$_);
Branch: 1 branch
BranchTrueFalseTotal
if ref($_[0] ||= $_) 3 2 5
Condition33%1/3
$_[0] ||= $_
l!l&&r!l&&!r
500
MC/DC0%0/2
$_[0] ||= $_
$_[0] $_
Truth table33%1/3
A ||= B
A= $_[0]B= $_
ABresult
1X1
011
000
36 2 ( _callback_for_nargs +@_ )->(@_)
37 }
« Perlude.pm ↑ Summary Perlude/builtins.pm »