Embed/File.pm

filter: Statementstmt 86.3% 57 / 66 Branchbran 50.0% 18 / 36 Conditioncond 33.3% 3 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 100% 13 / 13 Podpod 100% 5 / 5 totaltotal 71.1% 96 / 135 CC 23 SCAR 27.2
CC
23
Cov
70%
is_same_as
33.0
new
14.0
contents
3.0
CRAP 15.2
« Embed/OneFileAsModule.pm ↑ Summary Embed/Writer.pm »
1 package Data::Embed::File;
2  
3 # ABSTRACT: embed arbitrary data in a file
4  
5 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 9 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 9 ▶use English qw< -no_match_vars >;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 9 ▶use IO::Slice;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 9 ▶use Fcntl qw< :seek >;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 9 ▶use Log::Log4perl::Tiny qw< :easy >;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 9 ▶use Scalar::Util qw< refaddr blessed >;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 9 our $VERSION = '0.32'; # make indexer happy
14  
15 56 ▶sub new {
Subroutine new: called CC=8 SCAR=26.4
Pod documented
16 56 my $package = shift;
17 0 ▶ my $self = {(scalar(@_) && ref($_[0])) ? %{$_[0]} : @_};
Branch: 1 branch
BranchTrueFalseTotal
scalar @_ && ref $_[0] ? : 0 56 56
Condition33%1/3
scalar @_ and ref $_[0]
!ll&&!rl&&r
0560
MC/DC0%0/2
scalar @_ and ref $_[0]
scalar @_ ref $_[0]
Truth table33%1/3
A and B
A= scalar @_B= ref $_[0]
ABresult
0X0
100
111
18 56 for my $feature (qw< offset length >) {
19 LOGCROAK "$package new(): missing required field $feature"
20 unless defined($self->{$feature})
21 112 ▶ && $self->{$feature} =~ m{\A\d+\z}mxs;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{$feature} and $self->{$feature} =~ /\A\d+\z/msx 0 112 112
Condition33%1/3
defined $self->{$feature} and $self->{$feature} =~ /\A\d+\z/msx
!ll&&!rl&&r
00112
MC/DC0%0/2
defined $self->{$feature} and $self->{$feature} =~ /\A\d+\z/msx
defined $self->{$feature} $self->{$feature} =~ /\A\d+\z/msx
Truth table33%1/3
A and B
A= defined $self->{$feature}B= $self->{$feature} =~ /\A\d+\z/msx
ABresult
0X0
100
111
22 }
23 LOGDIE "$package new(): either filename or fh are required"
24 56 ▶ unless defined($self->{fh}) || defined($self->{filename});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"fh"} or defined $self->{"filename"} 0 56 56
Condition33%1/3
defined $self->{"fh"} or defined $self->{"filename"}
l!l&&r!l&&!r
5600
MC/DC0%0/2
defined $self->{"fh"} or defined $self->{"filename"}
defined $self->{"fh"} defined $self->{"filename"}
Truth table33%1/3
A or B
A= defined $self->{"fh"}B= defined $self->{"filename"}
ABresult
1X1
011
000
25 56 return bless $self, $package;
26 } ## end sub new
27  
28 21 ▶sub fh {
Subroutine fh: called CC=2 SCAR=7.0
Pod documented
29 21 my $self = shift;
30 21 ▶ if (!exists $self->{slicefh}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"slicefh"}) 21 0 21
31 84 my %args = map { $_ => $self->{$_} }
32 21 grep { defined $self->{$_} } qw< fh filename offset length >;
33 21 $self->{slicefh} = IO::Slice->new(%args);
34 }
35 21 return $self->{slicefh};
36 } ## end sub fh
37  
38 15 ▶sub contents {
Subroutine contents: called CC=3 SCAR=11.0
Pod documented
39 15 my $self = shift;
40 15 my $fh = $self->fh();
41 15 my $current = tell $fh;
42 15 seek $fh, 0, SEEK_SET;
43  
44 15 ▶ local $/ = wantarray() ? $/ : undef;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 10 5 15
45 15 my @retval = <$fh>;
46 15 seek $fh, $current, SEEK_SET;
47 15 ▶ return @retval if wantarray();
Branch: 1 branch
BranchTrueFalseTotal
if wantarray 10 5 15
48 5 return $retval[0];
49 } ## end sub contents
50  
51 5 ▶sub name { return shift->{name}; }
Subroutine name: called CC=1 SCAR=0.0
Pod documented
52  
53 4 ▶sub _dname {
Subroutine _dname: called CC=2 SCAR=8.1
54 4 my $name = shift->{name};
55 4 ▶ return $name if defined $name;
Branch: 1 branch
BranchTrueFalseTotal
if defined $name 4 0 4
56 0 return '';
57 }
58  
59 4 ▶sub is_same_as {
Subroutine is_same_as: called CC=12 SCAR=35.0
Pod documented
60 4 my ($self, $other) = @_;
61 4 ▶ return unless blessed($other);
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($other) 1 3 4
62 3 ▶ return unless $other->isa('Data::Embed::File');
Branch: 1 branch
BranchTrueFalseTotal
unless $other->isa("Data::Embed::File") 0 3 3
63  
64 # quick wins
65 3 ▶ return unless $self->{offset} == $other->{offset};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"offset"} == $other->{"offset"} 1 2 3
66 2 ▶ return unless $self->{length} == $other->{length};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"length"} == $other->{"length"} 0 2 2
67  
68 # names must be the same
69 2 ▶ return unless $self->_dname() eq $other->_dname();
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_dname eq $other->_dname 0 2 2
70  
71 # check data sources
72 2 ▶ if (defined $self->{fh}) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $self->{'fh'}) { } 2 0 2
elsif (defined $self->{'filename'}) { } 0 0 0
73 2 ▶ return unless defined $other->{fh};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $other->{"fh"} 0 2 2
74 2 return refaddr($self->{fh}) eq refaddr($other->{fh});
75 }
76 elsif (defined $self->{filename}) {
77 0 ▶ return unless defined $other->{filename}; # paranoid...
Branch: 1 branch
BranchTrueFalseTotal
unless defined $other->{"filename"} 0 0 0
78 0 ▶ if (ref $self->{filename}) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self->{"filename"}) 0 0 0
79 0 ▶ return unless ref $other->{filename};
Branch: 1 branch
BranchTrueFalseTotal
unless ref $other->{"filename"} 0 0 0
80 0 return refaddr($self->{filename}) eq refaddr($other->{filename});
81 }
82 0 return $self->{filename} eq $other->{filename};
83 } ## end elsif (defined $self->{filename...})
84 else { # paranoid!
85 0 return;
86 }
87  
88 0 return 1; # you made it!
89 } ## end sub is_same_as
90  
91 9 1;
« Embed/OneFileAsModule.pm ↑ Summary Embed/Writer.pm »