| 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
| |||||||||||||||
| 17 | |||||||||||||||
| 18 | croak('Ther is no (' . $options->{FilePath} . ').') | ||||||||||||||
| 19 | 2 | ▶ | unless -e $options->{FilePath}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 20 | |||||||||||||||
| 21 | 2 | ▶ | if ($options->{Type}) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 22 | $options->{Type} ='int' | ||||||||||||||
| 23 | 1 | ▶ | unless $options->{Type} eq 'char'; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 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
| |||||||||||||||
| 41 | 5 | foreach (0...1) { | |||||||||||||
| 42 | 10 | ▶ | if (length($times[$_]) > 4) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 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
| |||||||||||||||
| 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
| |||||||||||||||
| 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
| |||||||||||||||
| 80 | 5 | foreach (0...1) { | |||||||||||||
| 81 | 10 | ▶ | if ($times[$_]) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 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
| |||||||||||||||
| 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__ | ||||||||||||||