Dumpfile/Node/Content.pm

filter: Statementstmt 87.6% 78 / 89 Branchbran 57.6% 15 / 26 Conditioncond 40.0% 6 / 15 MC/DCmcdc 11.1% 1 / 9 Subroutinesub 100% 19 / 19 Podpod 100% 11 / 11 totaltotal 76.9% 130 / 169 CC 19 SCAR 14.1
CC
19
Cov
76%
save
10.5
write
7.1
load
4.8
CRAP 4.1
« Dumpfile/Node/Properties.pm ↑ Summary Dumpfile/Tutorial.pm »
1 ################################################################################
2 # Copyright (c) 2008 Martin Scharrer <martin@scharrer-online.de>
3 # This is open source software under the GPL v3 or later.
4 #
5 # $Id: Content.pm 103 2008-10-14 21:11:21Z martin $
6 ################################################################################
7 package SVN::Dumpfile::Node::Content;
8 12 ▶use IO::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 12 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 12 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 12 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 12 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 12 Readonly my $NL => chr(10);
14  
15 12 our $VERSION = do { '$Rev: 103 $' =~ /\$Rev: (\d+) \$/; '0.13' . ".$1" };
16  
17 use overload
18 12 ▶ '""' => \&as_string,
Subroutine BEGIN: called CC=1 SCAR=0.0
19 12 fallback => 1;
20  
21 46 ▶sub new {
Subroutine new: called CC=2 SCAR=7.4
Pod documented
22 46 my $class = shift;
23 46 my $scalar = shift;
24 46 ▶ my $self = bless \$scalar, ref $class || $class;
Condition33%1/3
ref $class || $class
l!l&&r!l&&!r
0460
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table33%1/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
25 46 return $self;
26 }
27  
28 6 ▶sub exists {
Subroutine exists: called CC=2 SCAR=7.1
Pod documented
29 6 my $self = shift;
30 6 ▶ return ( defined $$self and $$self ne '' );
Condition66%2/3
defined $$self && $$self ne ''
!ll&&!rl&&r
303
MC/DC50%1/2
defined $$self && $$self ne ''
defined $$self $$self ne ''
Truth table66%2/3
A && B
A= defined $$selfB= $$self ne ''
ABresult
0X0
100
111
31 }
32  
33 2 ▶sub delete {
Subroutine delete: called CC=1 SCAR=0.0
Pod documented
34 2 my $self = shift;
35 2 $$self = undef;
36 2 return;
37 }
38  
39 18 ▶sub value : lvalue {
Subroutine value: called CC=2 SCAR=6.9
Pod documented
40 18 my $self = shift;
41 18 my $newvalue = shift;
42 18 ▶ $$self = $newvalue
Branch: 1 branch
BranchTrueFalseTotal
if defined $newvalue 6 12 18
43 if defined $newvalue;
44 18 $$self;
45 }
46  
47 43 ▶sub as_string {
Subroutine as_string: called CC=2 SCAR=6.9
Pod documented
48 43 my $self = shift;
49 43 ▶ return ( ( defined $$self ) ? $$self : '' );
Branch: 1 branch
BranchTrueFalseTotal
defined $$self ? : 25 18 43
50 }
51  
52 12 *to_string = \&as_string;
53  
54 8 ▶sub read {
Subroutine read: called CC=1 SCAR=0.0
Pod documented
55 8 my ( $self, $fh, $length ) = @_;
56 8 return $fh->read( $$self, $length );
57 }
58  
59 5 ▶sub write {
Subroutine write: called CC=5 SCAR=19.6
Pod documented
60 5 my $self = shift;
61 5 my $fh = shift;
62  
63 5 ▶ unless ( eval { $fh->isa('IO::Handle') }
Branch: 1 branch
BranchTrueFalseTotal
unless (eval { do { $fh->isa("IO::Handle") } } or ref $fh eq "GLOB" or ref \$fh eq "GLOB") 0 5 5
Condition33%2/6
eval { do { $fh->isa("IO::Handle") } } or ref $fh eq "GLOB" or ref \$fh eq "GLOB"
l!l&&r!l&&!r
500
eval { do { $fh->isa("IO::Handle") } } or ref $fh eq "GLOB"
l!l&&r!l&&!r
500
MC/DC0%0/3
eval { do { $fh->isa("IO::Handle") } } or ref $fh eq "GLOB" or ref \$fh eq "GLOB"
eval { do { $fh->isa("IO::Handle") } } ref $fh eq "GLOB" ref \$fh eq "GLOB"
Truth table25%1/4
A or B or C
A= eval { do { $fh->isa("IO::Handle") } }B= ref $fh eq "GLOB"C= ref \$fh eq "GLOB"
ABCresult
1XX1
01X1
0011
0000
64 || ref $fh eq 'GLOB'
65 || ref \$fh eq 'GLOB' )
66 {
67 0 croak "Given argument is no valid file handle.";
68 }
69  
70 5 ▶ return ($$self) ? $fh->print($$self) : '0 but true';
Branch: 1 branch
BranchTrueFalseTotal
$$self ? : 5 0 5
71 }
72  
73 1 ▶sub save {
Subroutine save: called CC=6 SCAR=23.5
Pod documented
74 1 my ( $self, $fr ) = @_;
75 1 my $fh;
76 1 ▶ return unless defined $fr and defined $$self;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $fr and defined $$self 0 1 1
Condition33%1/3
defined $fr and defined $$self
!ll&&!rl&&r
001
MC/DC0%0/2
defined $fr and defined $$self
defined $fr defined $$self
Truth table33%1/3
A and B
A= defined $frB= defined $$self
ABresult
0X0
100
111
77  
78 # $fr can be filename or handle
79 1 ▶ if ( !ref $fr ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not ref $fr) { } 1 0 1
elsif (eval { do { $fr->can('print') } }) { } 0 0 0
80 1 $fh = eval { new IO::File $fr, '>' };
81 1 ▶ if ( !$fh ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($fh) 0 1 1
82 0 carp("Can't print to given filename!");
83 0 return;
84 }
85 1 $fh->binmode;
86 }
87 0 elsif ( eval { $fr->can('print') } ) {
88 0 $fh = $fr;
89 }
90 else {
91 0 carp("Can't print to given handle!");
92 0 return;
93 }
94 1 return $fh->print($$self);
95 }
96  
97 2 ▶sub load {
Subroutine load: called CC=4 SCAR=15.6
Pod documented
98 12 ▶ use bytes;
Subroutine BEGIN: called CC=1 SCAR=0.0
99 2 my ( $self, $fr ) = @_;
100 2 my $fh;
101  
102 # $fr can be filename or handle
103 2 ▶ if ( !ref $fr ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not ref $fr) { } 2 0 2
elsif (eval { do { $fr->can('getlines') } }) { } 0 0 0
104 2 $fh = eval { new IO::File $fr, '<' };
105 2 ▶ return unless $fh;
Branch: 1 branch
BranchTrueFalseTotal
unless $fh 0 2 2
106 2 $fh->binmode;
107 }
108 0 elsif ( eval { $fr->can('getlines') } ) {
109 0 $fh = $fr;
110 }
111 else {
112 0 carp "Can't print to given handle!";
113 0 return;
114 }
115  
116 2 $$self = join '', $fh->getlines;
117 2 return bytes::length($$self);
118 }
119  
120 3 ▶sub lines {
Subroutine lines: called CC=2 SCAR=6.9
Pod documented
121 3 my $self = shift;
122 3 my $lines = 0;
123 3 $lines = ( $self =~ tr/\012// );
124 3 ▶ $lines++ if $self !~ /$NL\Z/m;
Branch: 1 branch
BranchTrueFalseTotal
unless $self =~ /$NL\Z/m 2 1 3
125 3 return $lines; # Count lines
126 }
127  
128 17 ▶sub length {
Subroutine length: called CC=2 SCAR=6.9
Pod documented
129 12 ▶ use bytes;
Subroutine BEGIN: called CC=1 SCAR=0.0
130 17 my $self = shift;
131 17 ▶ return 0 unless defined $$self;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $$self 13 4 17
132 4 return bytes::length $$self;
133 }
134  
135 12 1;
136 __END__
« Dumpfile/Node/Properties.pm ↑ Summary Dumpfile/Tutorial.pm »