blib/lib/File/Storage/Stat.pm

filter: Statementstmt 98.1% 53 / 54 Branchbran 83.3% 20 / 24 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod 66.6% 2 / 3 totaltotal 93.0% 80 / 86 CC 16 SCAR 17.3
CC
16
Cov
94%
set
7.0
get
6.0
new
5.1
CRAP 5.6
↑ Summary
1 package File::Storage::Stat;
2  
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 3 require Exporter;
7  
8 3 our @ISA = qw(Exporter);
9 3 our $VERSION = '0.02';
10  
11 2 ▶sub new {
Subroutine new: called CC=5 SCAR=16.4
Pod undocumented
12 2 my $class = shift;
13 2 my $options = shift;
14  
15 croak('FilePath is not set.')
16 2 ▶ unless $options->{FilePath};
Branch: 1 branch
BranchTrueFalseTotal
unless $options->{"FilePath"} 0 2 2
17  
18 croak('Ther is no (' . $options->{FilePath} . ').')
19 2 ▶ unless -e $options->{FilePath};
Branch: 1 branch
BranchTrueFalseTotal
unless -e $options->{"FilePath"} 0 2 2
20  
21 2 ▶ if ($options->{Type}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options->{'Type'}) { } 1 1 2
22 $options->{Type} ='int'
23 1 ▶ unless $options->{Type} eq 'char';
Branch: 1 branch
BranchTrueFalseTotal
unless $options->{"Type"} eq "char" 0 1 1
24 } else {
25 1 $options->{Type} = 'int';
26 }
27  
28 my $self = {
29 FilePath => $options->{FilePath},
30 Type => $options->{Type},
31 2 };
32  
33 2 return bless $self, $class;
34 }
35  
36 48 ▶sub set {
Subroutine set: called CC=7 SCAR=19.5
Pod documented
37 48 my $self = shift;
38 48 my @times = (shift, shift);
39  
40 48 ▶ if ($self->{Type} eq 'char') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"Type"} eq "char") 5 43 48
41 5 foreach (0...1) {
42 10 ▶ if (length($times[$_]) > 4) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $times[$_] > 4) { } 2 8 10
43 2 $times[$_] = 0;
44 } else {
45 8 my $t = 0;
46 8 foreach (split('', $times[$_])) {
47 18 $t <<= 8;
48 18 $t += ord($_);
49 }
50 8 $times[$_] = $t;
51 }
52 }
53 }
54
55 @times = map {
56 48 my $v = $_;
57 96 ▶ if ($v < 0) {
Branch: 2 branches
BranchTrueFalseTotal
if ($v < 0) { } 1 95 96
elsif ($v >= 4294967296) { } 1 94 95
58 1 $v = 0;
59 } elsif ($v >= ((1 << 31) * 2)) {
60 1 $v = 0;
61 }
62 96 $v;
63 } @times;
64  
65 48 return utime($times[0], $times[1], $self->{FilePath});
66 }
67  
68 48 ▶sub get {
Subroutine get: called CC=6 SCAR=17.9
Pod documented
69 48 my $self = shift;
70  
71 my @times = map {
72 144 my $v = $_;
73 144 ▶ if ($v < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v < 0) 0 144 144
74 0 $v = $v + ((1 << 31) * 2);
75 }
76 144 $v;
77 48 } (stat $self->{FilePath})[8,9,10];
78  
79 48 ▶ if ($self->{Type} eq 'char') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"Type"} eq "char") 5 43 48
80 5 foreach (0...1) {
81 10 ▶ if ($times[$_]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($times[$_]) { } 6 4 10
82 6 my $t = '';
83 6 while (1) {
84 18 $t = chr($times[$_] % 256) . $t;
85 18 $times[$_] >>= 8;
86 18 ▶ last unless $times[$_];
Branch: 1 branch
BranchTrueFalseTotal
unless $times[$_] 6 12 18
87 }
88 6 $times[$_] = $t;
89 } else {
90 4 $times[$_] = '';
91 }
92 }
93 }
94  
95 48 return @times;
96 }
97  
98 3 1;
99 __END__
↑ Summary