lib/MAB2/Writer/Handle.pm

filter: Statementstmt 100% 37 / 37 Branchbran 60.0% 6 / 10 Conditioncond 22.2% 2 / 9 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 100% 13 / 13 Podpod 100% 2 / 2 totaltotal 80.0% 60 / 75 CC 10 SCAR 12.7
CC
10
Cov
80%
__ANON__
9.7
write
3.0
__ANON__
2.1
CRAP 3.5
« lib/MAB2/Writer/Disk.pm ↑ Summary lib/Catmandu/Exporter/MAB2.pm »
1 package MAB2::Writer::Handle;
2  
3 3 our $VERSION = '0.24';
4  
5 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use Encode qw(find_encoding);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 ▶use Scalar::Util qw(blessed openhandle);
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 has encoding => (
12 is => 'rw',
13 8 ▶ isa => sub {
Subroutine __ANON__: called CC=2 SCAR=7.6
14 8 ▶ find_encoding($_[0]) or croak "encoding \"$_[0]\" is not a valid encoding";
Branch: 1 branch
BranchTrueFalseTotal
&find_encoding($_[0]) or croak(qq[encoding "$_[0]" is not a valid encoding]) 8 0 8
15 },
16 7 ▶ default => sub { 'UTF-8' },
Subroutine __ANON__: called CC=1 SCAR=0.0
17 3 );
18  
19 has file => (
20 is => 'rw',
21 1 ▶ isa => sub {
Subroutine __ANON__: called CC=2 SCAR=7.6
22 1 ▶ croak 'expect file!' unless defined $_[0];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_[0] 0 1 1
23 },
24 3 trigger => \&_set_fh,
25 );
26  
27 has fh => (
28 is => 'rw',
29 9 ▶ isa => sub {
Subroutine __ANON__: called CC=5 SCAR=22.7
30 9 my $ishandle = eval { fileno( $_[0] ); };
31 9 ▶ croak 'expect filehandle or object with method print!'
Branch: 1 branch
BranchTrueFalseTotal
unless not $@ and defined $ishandle or builtin::blessed($_[0]) and $_[0]->can("print") 0 9 9
Condition22%2/9
not $@ and defined $ishandle or builtin::blessed($_[0]) and $_[0]->can("print")
l!l&&r!l&&!r
900
not $@ and defined $ishandle
!ll&&!rl&&r
009
builtin::blessed($_[0]) and $_[0]->can("print")
!ll&&!rl&&r
000
MC/DC0%0/4
not $@ and defined $ishandle or builtin::blessed($_[0]) and $_[0]->can("print")
not $@ defined $ishandle builtin::blessed($_[0]) $_[0]->can("print")
Truth table14%1/7
not(A) and B or C and D
A= not $@B= defined $ishandleC= builtin::blessed($_[0])D= $_[0]->can("print")
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
32 unless !$@ and defined $ishandle
33 or ( blessed $_[0] && $_[0]->can('print') );
34 },
35 1 ▶ default => sub { \*STDOUT }
Subroutine __ANON__: called CC=1 SCAR=0.0
36 3 );
37  
38 1 ▶sub _set_fh {
Subroutine _set_fh: called CC=2 SCAR=7.0
39 1 my ($self) = @_;
40  
41 1 my $encoding = $self->encoding;
42 1 ▶ open my $fh, ">:encoding($encoding)", $self->file
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">:encoding($encoding)", $self->file or croak("could not open file!") 1 0 1
43 or croak 'could not open file!';
44 1 $self->fh($fh);
45 }
46  
47 4 ▶sub close_fh {
Subroutine close_fh: called CC=1 SCAR=0.0
Pod documented
48 4 my ($self) = @_;
49  
50 4 close $self->{fh};
51 }
52  
53 16 ▶sub write {
Subroutine write: called CC=3 SCAR=11.0
Pod documented
54 16 my ($self, @records) = @_;
55  
56 16 foreach my $record (@records) {
57 16 ▶ $record = $record->{record} if ref $record eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $record eq "HASH" 8 8 16
58 16 $self->_write_record($record);
59 }
60 }
61  
62  
63 3 1;
64  
65 __END__
« lib/MAB2/Writer/Disk.pm ↑ Summary lib/Catmandu/Exporter/MAB2.pm »