blib/lib/VCS/Lite/Element/Binary.pm

filter: Statementstmt 100% 58 / 58 Branchbran 78.5% 11 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 9 / 9 Podpod 100% 1 / 1 totaltotal 96.3% 79 / 82 CC 9 SCAR 13.4
CC
9
Cov
96%
_contents
7.0
_slurp_lite
3.0
BEGIN
1.0
CRAP 3.8
« blib/lib/VCS/Lite/Common.pm ↑ Summary blib/lib/VCS/Lite/backends.pl »
1 package VCS::Lite::Element::Binary;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 our $VERSION = '0.11';
7  
8 #----------------------------------------------------------------------------
9  
10 2 ▶use base qw/VCS::Lite::Element/;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use File::Spec::Functions qw/:ALL !path/;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶use Params::Validate qw(:all);
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 2 our @CARP_NOT = qw/VCS::Lite::Element/;
16  
17 #----------------------------------------------------------------------------
18  
19 sub new {
20 1 ▶ my $pkg = shift;
Subroutine new: called CC=1 SCAR=0.0
Pod documented
21 1 my $name = shift;
22 1 my %args = validate ( @_,
23 {
24 store => 0, # Handled by SUPER::new
25 verbose => 0,
26 recordsize => { type => SCALAR, default => 128 },
27 } );
28 1 $pkg->SUPER::new($name,%args);
29 }
30  
31 sub _slurp_lite {
32 5 ▶ my $self = shift;
Subroutine _slurp_lite: called CC=3 SCAR=11.0
33 5 my $name = shift;
34 5 my $recsiz = $self->{recordsize};
35  
36 5 my $in;
37  
38 5 ▶ open $in,'<',$name or croak "$name: $!";
Branch: 1 branch
BranchTrueFalseTotal
open $in, "<", $name or croak("${name}: $!") 0 5 5
39 5 binmode $in;
40 5 my @fil;
41 my $buff;
42 5 ▶ while (sysread($in,$buff,$recsiz)) {
Branch: 1 branch
BranchTrueFalseTotal
if (sysread $in, $buff, $recsiz) 122 5 127
43 122 push @fil,$buff;
44 }
45 5 VCS::Lite->new($name,undef,\@fil);
46 }
47  
48 sub _contents {
49 7 ▶ my $self = shift;
Subroutine _contents: called CC=7 SCAR=19.5
50  
51 7 my $recsiz = $self->{recordsize};
52 7 my $bin = $self->{store}->store_path($self->path,'vbin');
53 7 my $cont;
54 7 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 2 5 7
55 2 $cont = shift;
56 2 my $out;
57 2 ▶ open $out,'>',$bin or croak "$bin: $!";
Branch: 1 branch
BranchTrueFalseTotal
open $out, ">", $bin or croak("${bin}: $!") 0 2 2
58 2 binmode $out;
59 2 for (@$cont) {
60 101 my $str = pack 'n',length $_;
61 101 syswrite($out,$str.$_);
62 }
63 } else {
64 5 ▶ return [] unless -f $bin;
Branch: 1 branch
BranchTrueFalseTotal
unless -f $bin 2 3 5
65 3 my $in;
66  
67 3 ▶ open $in,'<',$bin or croak "$bin: $!";
Branch: 1 branch
BranchTrueFalseTotal
open $in, "<", $bin or croak("${bin}: $!") 0 3 3
68 3 binmode $in;
69 3 my @fil;
70 my $buff;
71 3 ▶ while (sysread($in,$buff,2)) {
Branch: 1 branch
BranchTrueFalseTotal
if (sysread $in, $buff, 2) 170 3 173
72 170 my $rsz = unpack 'n',$buff;
73 170 sysread($in,$buff,$rsz);
74 170 push @fil,$buff;
75 }
76 3 $cont = \@fil;
77 }
78 5 $cont;
79 }
80
81 2 1; #this line is important and will help the module return a true value
82  
83 __END__
« blib/lib/VCS/Lite/Common.pm ↑ Summary blib/lib/VCS/Lite/backends.pl »