| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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}
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}
| |||||||||||||||||||||||||||||
| 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
Condition33%1/3
$_[0] ||= $_
MC/DC0%0/2
$_[0] ||= $_
$_[0]
$_
Truth table33%1/3
A ||= B
A= $_[0]B= $_
| |||||||||||||||||||||||||||||
| 36 | 2 | ( _callback_for_nargs +@_ )->(@_) | |||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||