lib/Catmandu/Exporter/MAB2.pm

filter: Statementstmt 95.1% 39 / 41 Branchbran 91.6% 11 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 90.9% 10 / 11 Podpod 100% 2 / 2 totaltotal 93.9% 62 / 66 CC 7 SCAR 7.9
CC
7
Cov
94%
_build_writer
4.1
add
3.0
commit
2.0
CRAP 2.2
« lib/MAB2/Writer/Handle.pm ↑ Summary lib/Catmandu/Importer/MAB2.pm »
1 package Catmandu::Exporter::MAB2;
2  
3 1 our $VERSION = '0.24';
4  
5 2 ▶use Catmandu::Sane;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use MAB2::Writer::Disk;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use MAB2::Writer::RAW;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use MAB2::Writer::XML;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 with 'Catmandu::Exporter';
12  
13 0 ▶has type => ( is => 'ro', default => sub {'raw'} );
Subroutine __ANON__: not called CC=1 SCAR=1.2
14 2 ▶has xml_declaration => ( is => 'ro', default => sub {0} );
Subroutine __ANON__: called CC=1 SCAR=0.0
15 2 ▶has collection => ( is => 'ro', default => sub {0} );
Subroutine __ANON__: called CC=1 SCAR=0.0
16 1 has writer => ( is => 'lazy' );
17  
18 3 ▶sub _build_writer {
Subroutine _build_writer: called CC=4 SCAR=14.0
19 3 my ($self) = @_;
20  
21 3 my $type = lc( $self->{type} );
22 3 ▶ if ( $type eq 'raw' ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($type eq 'raw') { } 1 2 3
elsif ($type eq 'disk') { } 1 1 2
elsif ($type eq 'xml') { } 1 0 1
23 1 MAB2::Writer::RAW->new( fh => $self->fh );
24 }
25 elsif ( $type eq 'disk' ) {
26 1 MAB2::Writer::Disk->new( fh => $self->fh );
27 }
28 elsif ( $type eq 'xml' ) {
29 1 MAB2::Writer::XML->new(
30 fh => $self->fh,
31 xml_declaration => $self->xml_declaration,
32 collection => $self->collection
33 );
34 }
35 else {
36 0 die "unknown type: $type";
37 }
38 }
39  
40 6 ▶sub add {
Subroutine add: called CC=3 SCAR=11.0
Pod documented
41 6 my ( $self, $data ) = @_;
42  
43 6 ▶ if ( !$self->count ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->count) 3 3 6
44 3 ▶ if ( lc( $self->type ) eq 'xml' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (lc $self->type eq "xml") 1 2 3
45 1 $self->writer->start();
46 }
47 }
48  
49 6 $self->writer->write($data);
50  
51 }
52  
53 3 ▶sub commit {
Subroutine commit: called CC=2 SCAR=6.9
Pod documented
54 3 my ($self) = @_;
55 3 ▶ if ( $self->collection ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->collection) 1 2 3
56 1 $self->writer->end();
57 }
58 3 $self->writer->close_fh();
59  
60 }
61
62  
63 1 1;
64  
65 __END__
« lib/MAB2/Writer/Handle.pm ↑ Summary lib/Catmandu/Importer/MAB2.pm »