| 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.0'; | |||||||||||||||||||||||||||||||||||||||||
| 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 | 1 | ▶ | 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 | sub rotate { | ||||||||||||||||||||||||||||||||||||||||||
| 98 | 11 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
rotate: called CC=15 SCAR=28.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | 11 | ▶ | unless (is_blessed_ref $self) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 101 | 5 | ▶ | 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 | 11 | my $max = $self->max; | |||||||||||||||||||||||||||||||||||||||||
| 114 | 11 | ▶ | my $age = ($self->age) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 115 | ? $self->_epoch - ($self->age * ONE_DAY) | ||||||||||||||||||||||||||||||||||||||||||
| 116 | : 0; | ||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||
| 118 | 11 | my @files = @{ $self->_build_files_to_rotate }; | |||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||
| 120 | 11 | my $index = scalar( @files ); | |||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||
| 122 | 11 | ▶ | while ($index--) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||
| 124 | 22 | ▶ | my $file = $files[$index] or next; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||
| 126 | 22 | my $current = $file->{current}; | |||||||||||||||||||||||||||||||||||||||||
| 127 | 22 | my $rotated = $file->{rotated}; | |||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||
| 129 | 22 | ▶ | unless (defined $rotated) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 130 | 1 | $current->remove; | |||||||||||||||||||||||||||||||||||||||||
| 131 | 1 | next; | |||||||||||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||
| 134 | 21 | ▶ | 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 | 21 | ▶ | if ($age && $current->stat->mtime < $age) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$age and $current->stat->mtime < $age
MC/DC100%2/2
$age and $current->stat->mtime < $age
$age
$current->stat->mtime < $age
Truth table100%3/3
A and B
A= $ageB= $current->stat->mtime < $age
| |||||||||||||||||||||||||||||||||||||||||||
| 140 | 1 | $current->remove; | |||||||||||||||||||||||||||||||||||||||||
| 141 | 1 | next; | |||||||||||||||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||
| 144 | 20 | ▶ | die "Cannot move ${current} -> ${rotated}: file exists" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 145 | if $rotated->exists; | ||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||
| 147 | 20 | $current->move($rotated); | |||||||||||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||
| 150 | 11 | ▶ | $self->file->touch if $self->touch; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||
| 152 | # TODO: chmod/chown arguments | ||||||||||||||||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||
| 156 | sub _build_files_to_rotate { | ||||||||||||||||||||||||||||||||||||||||||
| 157 | 11 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_files_to_rotate: called CC=16 SCAR=27.8
| |||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||
| 159 | 11 | my %files; | |||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||
| 161 | 11 | my $num = $self->start_num; | |||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||
| 163 | 11 | my $file = $self->_rotated_name( $num ); | |||||||||||||||||||||||||||||||||||||||||
| 164 | 11 | my $orig = $self->file; | |||||||||||||||||||||||||||||||||||||||||
| 165 | 11 | ▶ | 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 | 4 | $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 | 11 | my $max = $self->max; | |||||||||||||||||||||||||||||||||||||||||
| 179 | 11 | ▶ | while ($file->exists || ($max && $num <= $max)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$file->exists or $max and $num <= $max
$max and $num <= $max
MC/DC66%2/3
$file->exists or $max and $num <= $max
$file->exists
$max
$num <= $max
Truth table75%3/4
A or B and C
A= $file->existsB= $maxC= $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) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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 | 11 | my $g = Graph->new; | |||||||||||||||||||||||||||||||||||||||||
| 201 | 11 | foreach my $file (values %files) { | |||||||||||||||||||||||||||||||||||||||||
| 202 | 22 | my $current = $file->{current}; | |||||||||||||||||||||||||||||||||||||||||
| 203 | 22 | ▶ | if (my $rotated = $file->{rotated}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 204 | 21 | $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 | 11 | my %rotated; | |||||||||||||||||||||||||||||||||||||||||
| 215 | 11 | $rotated{$_->[1]}++ for ($g->edges); | |||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||
| 217 | 11 | ▶ | 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 | 11 | ▶ | die "dependency chain is cyclic" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 222 | if $g->has_a_cycle; | ||||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||
| 224 | return [ | ||||||||||||||||||||||||||||||||||||||||||
| 225 | 29 | grep { defined $_ } | |||||||||||||||||||||||||||||||||||||||||
| 226 | 11 | map { $files{$_} } $g->topological_sort() | |||||||||||||||||||||||||||||||||||||||||
| 227 | ]; | ||||||||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||||||||||
| 232 | sub _rotated_name { | ||||||||||||||||||||||||||||||||||||||||||
| 233 | 137 | ▶ | my ($self, $index) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_rotated_name: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||||||||||
| 235 | 137 | my $format = $self->extension_format; | |||||||||||||||||||||||||||||||||||||||||
| 236 | { | ||||||||||||||||||||||||||||||||||||||||||
| 237 | 5 | ▶ | no warnings 'uninitialized'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 238 | 137 | $format =~ s/\%(\d+)*#/sprintf("\%0$1d", $index)/gea; | |||||||||||||||||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||||||||
| 241 | 137 | my $file = $self->file->stringify; | |||||||||||||||||||||||||||||||||||||||||
| 242 | 137 | ▶ | my $extension = ($format =~ /\%/) ? $self->_strftime($format) : $format; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 243 | 137 | my $replace = $self->replace_extension; | |||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||
| 245 | 137 | ▶ | 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 | 133 | return path( $file . $extension ); | |||||||||||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||||
| 258 | sub rotate_files { | ||||||||||||||||||||||||||||||||||||||||||
| 259 | 1 | ▶ | __PACKAGE__->rotate( @_ ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
rotate_files: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||||||||||||
| 263 | 5 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||||||||||||||||
| 265 | __END__ | ||||||||||||||||||||||||||||||||||||||||||