| 1 | package Egg::Model::FsaveDate::Base; | ||||||||||||||||||||||||||||||||||||||
| 2 | # | ||||||||||||||||||||||||||||||||||||||
| 3 | # Masatoshi Mizuno E<lt>lusheE<64>cpan.orgE<gt> | ||||||||||||||||||||||||||||||||||||||
| 4 | # | ||||||||||||||||||||||||||||||||||||||
| 5 | # $Id: Base.pm 283 2008-02-27 05:27:43Z lushe $ | ||||||||||||||||||||||||||||||||||||||
| 6 | # | ||||||||||||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 8 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 9 | 3 | ▶ | use Carp qw/ croak /; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 10 | 3 | ▶ | use base qw/ Egg::Base /; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 11 | 3 | ▶ | use File::Path; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 12 | 3 | ▶ | use FileHandle; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||
| 14 | 3 | our $VERSION= '0.01'; | |||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||
| 16 | 1 | ▶ | sub save { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
save: called CC=11 SCAR=28.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 17 | 1 | my $self= shift; | |||||||||||||||||||||||||||||||||||||
| 18 | 1 | ▶ | my $body= shift || croak q{ I want save data. }; | ||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
shift() || croak(' I want save data. ')
MC/DC0%0/1
shift() || croak(' I want save data. ')
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||
| 19 | 1 | ▶ | my $c= $self->config || $self->config_to(qw/ Model FsaveDate /); | ||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$self->config || $self->config_to('Model', 'FsaveDate')
MC/DC0%0/2
$self->config || $self->config_to('Model', 'FsaveDate')
$self->config
$self->config_to('Model', 'FsaveDate')
Truth table33%1/3
A || B
A= $self->configB= $self->config_to('Model', 'FsaveDate')
| |||||||||||||||||||||||||||||||||||||||
| 20 | my $base= shift || | ||||||||||||||||||||||||||||||||||||||
| 21 | 1 | ▶ | do { $c->{base_path} ||= $self->e->path_to(qw{ etc FsaveDate }) }; | ||||||||||||||||||||||||||||||||||||
|
Condition33%2/6
shift() || do {
$c->{'base_path'} ||= $self->e->path_to('etc', 'FsaveDate')
}
$c->{"base_path"} ||= $self->e->path_to("etc", "FsaveDate")
MC/DC0%0/2
shift() || do {
$c->{'base_path'} ||= $self->e->path_to('etc', 'FsaveDate')
}
shift()
do {
$c->{'base_path'} ||= $self->e->path_to('etc', 'FsaveDate')
}
MC/DC0%0/2
$c->{"base_path"} ||= $self->e->path_to("etc", "FsaveDate")
$c->{"base_path"}
$self->e->path_to("etc", "FsaveDate")
Truth table33%1/3
A || B
A= shift()B= do {
$c->{'base_path'} ||= $self->e->path_to('etc', 'FsaveDate')
}
Truth table33%1/3
A ||= B
A= $c->{"base_path"}B= $self->e->path_to("etc", "FsaveDate")
| |||||||||||||||||||||||||||||||||||||||
| 22 | 1 | my $path= "$base/". $self->create_dir_name( time ); | |||||||||||||||||||||||||||||||||||||
| 23 | 1 | ▶ | unless ( -e $path ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 24 | 1 | ▶ | my $count= $c->{amount_save} || 90; | ||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$c->{'amount_save'} || 90
MC/DC0%0/1
$c->{'amount_save'} || 90
$c->{'amount_save'}
Truth table50%1/2
A
A= $c->{'amount_save'}
| |||||||||||||||||||||||||||||||||||||||
| 25 | 0 | ▶ | for my $dir (sort{$b cmp $a}(<$base/*>)) { ## no critic. | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.1
| |||||||||||||||||||||||||||||||||||||||
| 26 | 0 | ▶ | next if --$count> 0; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 27 | 0 | rmtree($dir); | |||||||||||||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||||||||||||
| 29 | 1 | mkpath($path, 0, 0755); ## no critic. | |||||||||||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||||||||||||
| 31 | 1 | ▶ | my $ext= $c->{extention} || 'txt'; $ext=~s{^\.+} []; | ||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$c->{'extention'} || 'txt'
MC/DC0%0/1
$c->{'extention'} || 'txt'
$c->{'extention'}
Truth table50%1/2
A
A= $c->{'extention'}
| |||||||||||||||||||||||||||||||||||||||
| 32 | 1 | my $fname= $self->create_file_name(\$body); | |||||||||||||||||||||||||||||||||||||
| 33 | 1 | my $output_path= "${path}/${fname}.${ext}"; | |||||||||||||||||||||||||||||||||||||
| 34 | 1 | ▶ | my $fh= FileHandle->new("> $output_path") | ||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
'FileHandle'->new("> $output_path") || die(" save error ($path/$fname.$ext): $! ")
MC/DC0%0/1
'FileHandle'->new("> $output_path") || die(" save error ($path/$fname.$ext): $! ")
'FileHandle'->new("> $output_path")
Truth table50%1/2
A
A= 'FileHandle'->new("> $output_path")
| |||||||||||||||||||||||||||||||||||||||
| 35 | || die qq{ save error (${path}/${fname}.${ext}): $! }; | ||||||||||||||||||||||||||||||||||||||
| 36 | 1 | print $fh $self->create_body(\$body); | |||||||||||||||||||||||||||||||||||||
| 37 | 1 | $fh->close; | |||||||||||||||||||||||||||||||||||||
| 38 | 1 | $output_path; | |||||||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||||||||
| 40 | 1 | ▶ | sub create_dir_name { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
create_dir_name: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 41 | 1 | my $self= shift; | |||||||||||||||||||||||||||||||||||||
| 42 | 1 | ▶ | my @t= localtime( shift || time ); | ||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
shift() || time
MC/DC0%0/1
shift() || time
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||
| 43 | 1 | sprintf("%02d%02d", ($t[5]+ 1900), ++$t[4], $t[3]); | |||||||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||||||
| 45 | 1 | ▶ | sub create_file_name { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
create_file_name: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 46 | 1 | my($self, $body)= @_; | |||||||||||||||||||||||||||||||||||||
| 47 | 1 | require Digest::SHA1; | |||||||||||||||||||||||||||||||||||||
| 48 | 1 | Digest::SHA1::sha1_hex($$body); | |||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||
| 50 | 1 | ▶ | sub create_body { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
create_body: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 51 | 1 | my($self, $body)= @_; | |||||||||||||||||||||||||||||||||||||
| 52 | 1 | return $$body; | |||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||
| 55 | 3 | 1; | |||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||
| 57 | __END__ | ||||||||||||||||||||||||||||||||||||||