| 1 | package File::Rotate::Simple; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 5 | ▶ | use v5.14; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 5 | ▶ | use Moo 1.001000; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 5 | extends 'Exporter'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 5 | ▶ | use Graph; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 5 | ▶ | use List::Util 1.43, qw/ first /; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 5 | ▶ | use Module::Runtime qw/ require_module /; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 5 | ▶ | use Path::Tiny 0.015; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 5 | ▶ | use Ref::Util qw/ is_blessed_ref /; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 5 | ▶ | use Time::Seconds qw/ ONE_DAY /; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 5 | ▶ | use Types::Standard -types; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 5 | ▶ | use namespace::autoclean; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 5 | our $VERSION = 'v0.4.2'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | # ABSTRACT: no-frills file rotation | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | # RECOMMEND PREREQ: Class::Load::XS | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | # RECOMMEND PREREQ: Ref::Util::XS | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | # RECOMMEND PREREQ: Type::Tiny::XS | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 5 | our @EXPORT_OK = qw/ rotate_files /; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 5 | has age => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | is => 'ro', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | isa => Int, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | default => 0, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 5 | has max => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | is => 'ro', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | isa => Int, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | default => 0, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 5 | has file => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | is => 'ro', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | isa => InstanceOf['Path::Tiny'], | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | coerce => \&path, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | required => 1, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 5 | has start_num => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | is => 'ro', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | isa => Int, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | default => 1, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 5 | has extension_format => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | is => 'ro', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | isa => Str, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | default => '.%#', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 5 | has replace_extension => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | is => 'ro', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | isa => Maybe[Str], | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 5 | has if_missing => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | is => 'ro', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | isa => Bool, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | default => 1, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 5 | has touch => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | is => 'ro', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | isa => Bool, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | default => 0, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | has time => ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | is => 'rw', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | isa => InstanceOf[qw/ Time::Piece Time::Moment DateTime DateTime::Lite DateTime::Tiny /], | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | lazy => 1, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 3 | ▶ | default => sub { require_module('Time::Piece'); Time::Piece::localtime() }, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 5 | handles => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | _strftime => 'strftime', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | _epoch => 'epoch', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | }, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 13 | ▶ | sub rotate { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
rotate: called CC=17 SCAR=30.2
Pod
documented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 13 | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 13 | ▶ | unless (is_blessed_ref $self) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | ▶ | my %args = (@_ == 1) ? %{ $_[0] } : @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 5 | ▶ | if (my $files = delete $args{files}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | foreach my $file (@{$files}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | $self->new( %args, file => $file )->rotate; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 5 | $self = $self->new(%args); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 13 | my $max = $self->max; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 13 | ▶ | my $age = ($self->age) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | ? $self->_epoch - ($self->age * ONE_DAY) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | : 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 13 | my @files = @{ $self->_build_files_to_rotate }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 13 | my $index = scalar( @files ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 13 | ▶ | while ($index--) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 24 | ▶ | my $file = $files[$index] or next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 24 | my $current = $file->{current}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 24 | my $rotated = $file->{rotated}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 24 | ▶ | unless (defined $rotated) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 1 | $current->remove; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 1 | next; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 23 | ▶ | if ($max && $index >= $max) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$max and $index >= $max
MC/DC0%0/2
$max and $index >= $max
$max
$index >= $max
Truth table66%2/3
A and B
A= $maxB= $index >= $max
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 0 | $current->remove; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | next; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 23 | ▶ | if ( $age && ( ( $current->exists || -l $current ) && $current->lstat->mtime < $age ) ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition77%7/9
$age and ($current->exists || -l $current and $current->lstat->mtime < $age)
$current->exists || -l $current and $current->lstat->mtime < $age
$current->exists or -l $current
MC/DC50%2/4
$age and ($current->exists || -l $current and $current->lstat->mtime < $age)
$age
$current->exists
-l $current
$current->lstat->mtime < $age
Truth table66%4/6
A and B or C and D
A= $ageB= $current->existsC= -l $currentD= $current->lstat->mtime < $age
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 1 | $current->remove; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 1 | next; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 22 | ▶ | die "Cannot move ${current} -> ${rotated}: file exists" | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | if $rotated->exists; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 22 | $current->move($rotated); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 13 | ▶ | $self->file->touch if $self->touch; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | # TODO: chmod/chown arguments | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 13 | ▶ | sub _build_files_to_rotate { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_files_to_rotate: called CC=18 SCAR=29.1
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 13 | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 13 | my %files; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 13 | my $num = $self->start_num; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 13 | my $file = $self->_rotated_name( $num ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 13 | my $orig = $self->file; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 13 | ▶ | if ( $orig->exists || -l $orig ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$orig->exists or -l $orig
MC/DC100%2/2
$orig->exists or -l $orig
$orig->exists
-l $orig
Truth table100%3/3
A or B
A= $orig->existsB= -l $orig
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 6 | $files{ $orig } = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | current => $orig, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | rotated => $file, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | } else { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 7 | ▶ | return [ ] unless $self->if_missing; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 13 | my $max = $self->max; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 13 | ▶ | while ($file->exists || -l $file || ($max && $num <= $max)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition88%8/9
$file->exists or -l $file or $max and $num <= $max
$file->exists or -l $file
$max and $num <= $max
MC/DC75%3/4
$file->exists or -l $file or $max and $num <= $max
$file->exists
-l $file
$max
$num <= $max
Truth table80%4/5
A or B or C and D
A= $file->existsB= -l $fileC= $maxD= $num <= $max
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 19 | my $rotated = $self->_rotated_name( ++$num ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 19 | ▶ | last if $rotated eq $file; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 19 | ▶ | if ( $file->exists || -l $file ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$file->exists or -l $file
MC/DC50%1/2
$file->exists or -l $file
$file->exists
-l $file
Truth table66%2/3
A or B
A= $file->existsB= -l $file
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 18 | ▶ | $files{ $file } = { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not $max or $num <= $max
MC/DC100%2/2
not $max or $num <= $max
not $max
$num <= $max
Truth table100%3/3
not(A) or B
A= not $maxB= $num <= $max
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | current => $file, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | rotated => (!$max || $num <= $max) ? $rotated : undef, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 19 | $file = $rotated; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | # Using a topoligical sort is probably overkill, but it allows us | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | # to use more complicated filename rotation schemes in a subclass | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | # without having to worry about file order. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 13 | my $g = Graph->new; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 13 | foreach my $file (values %files) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 24 | my $current = $file->{current}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 24 | ▶ | if (my $rotated = $file->{rotated}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 23 | $g->add_edge( $current->stringify, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | $rotated->stringify ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | } else { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 1 | $g->add_vertex( $current->stringify ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | # Now check that there is not more than one file being rotated to | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | # the same name. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 13 | my %rotated; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 13 | $rotated{$_->[1]}++ for ($g->edges); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 13 | ▶ | if (my $duplicate = first { $rotated{$_} > 1 } keys %rotated) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.2
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 0 | die "multiple files are rotated to '${duplicate}'"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 13 | ▶ | die "dependency chain is cyclic" | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | if $g->has_a_cycle; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | return [ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 33 | grep { defined $_ } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 13 | map { $files{$_} } $g->topological_sort() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 139 | ▶ | sub _rotated_name { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_rotated_name: called CC=3 SCAR=11.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 139 | my ($self, $index) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 139 | my $format = $self->extension_format; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 5 | ▶ | no warnings 'uninitialized'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 139 | $format =~ s/\%(\d+)*#/sprintf("\%0$1d", $index)/gea; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 139 | my $file = $self->file->stringify; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 139 | ▶ | my $extension = ($format =~ /\%/) ? $self->_strftime($format) : $format; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 139 | my $replace = $self->replace_extension; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 139 | ▶ | if (defined $replace) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 4 | my $re = quotemeta($replace); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 4 | return path($file =~ s/${re}$/${extension}/r ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | } else { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 135 | return path( $file . $extension ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 1 | ▶ | sub rotate_files { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
rotate_files: called CC=1 SCAR=0.0
Pod
documented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 1 | __PACKAGE__->rotate( @_ ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 5 | 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | __END__ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||