IOMux/File/Write.pm

filter: Statementstmt 93.7% 45 / 48 Branchbran 65.0% 13 / 20 Conditioncond 50.0% 4 / 8 MC/DCmcdc 20.0% 1 / 5 Subroutinesub 90.0% 9 / 10 Podpod 66.6% 2 / 3 totaltotal 78.7% 74 / 94 CC 14 SCAR 24.0
CC
14
Cov
82%
init
17.4
mode
2.0
BEGIN
1.0
CRAP 11.1
« IOMux.pm ↑ Summary IOMux/Poll.pm »
1 # Copyrights 2011-2020 by [Mark Overmeer <markov@cpan.org>].
2 # For other contributors see ChangeLog.
3 # See the manual pages for details on the licensing terms.
4 # Pod stripped from pm file by OODoc 2.02.
5 # This code is part of distribution IOMux. Meta-POD processed with OODoc
6 # into POD and HTML manual-pages. See README.md
7 # Copyright Mark Overmeer. Licensed under the same terms as Perl itself.
8  
9 package IOMux::File::Write;
10 3 ▶use vars '$VERSION';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 3 $VERSION = '1.01';
12  
13 3 ▶use base 'IOMux::Handler::Write';
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 3 ▶use Log::Report 'iomux';
Subroutine BEGIN: called CC=1 SCAR=0.0
19 3 ▶use Fcntl;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 3 ▶use File::Basename 'basename';
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22  
23 sub init($)
24 4 ▶{ my ($self, $args) = @_;
Subroutine init: called CC=14 SCAR=28.6
Pod undocumented
25  
26 my $file = $args->{file}
27 4 ▶ or error __x"no file to open specified in {pkg}", pkg => __PACKAGE__;
Branch: 1 branch
BranchTrueFalseTotal
my $file = $args->{"file"} or &error(&__x("no file to open specified in {pkg}", "pkg", __PACKAGE__)) 4 0 4
28  
29 4 my $flags = $args->{modeflags};
30 4 ▶ my $mode = $args->{mode} || '>';
Condition100%2/2
$args->{'mode'} || '>'
l!l
22
MC/DC100%1/1
$args->{'mode'} || '>'
$args->{'mode'}
Truth table100%2/2
A
A= $args->{'mode'}
Aresult
11
00
31 4 ▶ unless(ref $file || defined $flags)
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $file or defined $flags) 4 0 4
Condition33%1/3
ref $file or defined $flags
l!l&&r!l&&!r
004
MC/DC0%0/2
ref $file or defined $flags
ref $file defined $flags
Truth table33%1/3
A or B
A= ref $fileB= defined $flags
ABresult
1X1
011
000
32 4 ▶ { if($mode eq '>>') { $args->{append} = 1 }
Branch: 2 branches
BranchTrueFalseTotal
if ($mode eq '>>') { } 1 3 4
elsif ($mode eq '>') { } 3 0 3
33 3 ▶ elsif($mode eq '>') { $mode = '>>' if $args->{append} }
Branch: 1 branch
BranchTrueFalseTotal
if $args->{"append"} 1 2 3
34 else
35 0 { error __x"unknown file mode '{mode}' for {fn} in {pkg}"
36 , mode => $mode, fn => $file, pkg => __PACKAGE__;
37 }
38
39 4 $flags = O_WRONLY|O_NONBLOCK;
40 4 ▶ $flags |= O_CREAT unless exists $args->{create} && !$args->{create};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $args->{"create"} and not $args->{"create"} 4 0 4
Condition33%1/3
exists $args->{"create"} and not $args->{"create"}
!ll&&!rl&&r
400
MC/DC0%0/2
exists $args->{"create"} and not $args->{"create"}
exists $args->{"create"} not $args->{"create"}
Truth table33%1/3
A and not(B)
A= exists $args->{"create"}B= not $args->{"create"}
ABresult
0X0
100
111
41 4 ▶ $flags |= O_APPEND if $args->{append};
Branch: 1 branch
BranchTrueFalseTotal
if $args->{"append"} 2 2 4
42 4 ▶ $flags |= O_EXCL if $args->{exclusive};
Branch: 1 branch
BranchTrueFalseTotal
if $args->{"exclusive"} 0 4 4
43 }
44  
45 4 my $fh;
46 4 ▶ if(ref $file)
Branch: 1 branch
BranchTrueFalseTotal
if (ref $file) { } 0 4 4
47 0 { $fh = $file;
48 }
49 else
50 4 ▶ { sysopen $fh, $file, $flags
Branch: 1 branch
BranchTrueFalseTotal
sysopen $fh, $file, $flags or &fault(&__x("cannot open file {fn} for {pkg}", "fn", $file, "pkg", __PACKAGE__)) 4 0 4
51 or fault __x"cannot open file {fn} for {pkg}"
52 , fn => $file, pkg => __PACKAGE__;
53 4 $self->{IMFW_mode} = $flags;
54 }
55 4 $args->{name} = $mode.(basename $file);
56 4 $args->{fh} = $fh;
57  
58 4 $self->SUPER::init($args);
59 4 $self;
60 }
61  
62  
63 sub open($$@)
64 2 ▶{ my ($class, $mode, $file, %args) = @_;
Subroutine open: called CC=1 SCAR=0.0
Pod documented
65 2 $class->new(file => $file, mode => $mode, %args);
66 }
67  
68  
69 #-------------------
70  
71 0 ▶sub mode() {shift->{IMFW_mode}}
Subroutine mode: not called CC=1 SCAR=6.9
Pod documented
72  
73 3 1;
« IOMux.pm ↑ Summary IOMux/Poll.pm »