Model/FsaveDate/Base.pm

filter: Statementstmt 94.2% 49 / 52 Branchbran 25.0% 1 / 4 Conditioncond 42.1% 8 / 19 MC/DCmcdc 0.0% 0 / 11 Subroutinesub 100% 11 / 11 Podpod 100% 4 / 4 totaltotal 72.2% 73 / 101 CC 12 SCAR 21.8
CC
12
Cov
77%
save
16.4
create_dir_name
2.0
BEGIN
1.0
CRAP 8.8
↑ Summary Helper/Model/FsaveDate.pm »
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. ')
l!l
10
MC/DC0%0/1
shift() || croak(' I want save data. ')
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
19 1 ▶ my $c= $self->config || $self->config_to(qw/ Model FsaveDate /);
Condition33%1/3
$self->config || $self->config_to('Model', 'FsaveDate')
l!l&&r!l&&!r
010
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')
ABresult
1X1
011
000
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') }
l!l&&r!l&&!r
010
$c->{"base_path"} ||= $self->e->path_to("etc", "FsaveDate")
l!l&&r!l&&!r
010
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') }
ABresult
1X1
011
000
Truth table33%1/3
A ||= B
A= $c->{"base_path"}B= $self->e->path_to("etc", "FsaveDate")
ABresult
1X1
011
000
22 1 my $path= "$base/". $self->create_dir_name( time );
23 1 ▶ unless ( -e $path ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-e $path) 1 0 1
24 1 ▶ my $count= $c->{amount_save} || 90;
Condition50%1/2
$c->{'amount_save'} || 90
l!l
01
MC/DC0%0/1
$c->{'amount_save'} || 90
$c->{'amount_save'}
Truth table50%1/2
A
A= $c->{'amount_save'}
Aresult
11
00
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
BranchTrueFalseTotal
if --$count > 0 0 0 0
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'
l!l
01
MC/DC0%0/1
$c->{'extention'} || 'txt'
$c->{'extention'}
Truth table50%1/2
A
A= $c->{'extention'}
Aresult
11
00
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): $! ")
l!l
10
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")
Aresult
11
00
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
l!l
10
MC/DC0%0/1
shift() || time
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
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__
↑ Summary Helper/Model/FsaveDate.pm »