Cmd/OutputHandle.pm

filter: Statementstmt 57.5% 19 / 33 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 80.0% 4 / 5 Podpod n/a totaltotal 41.8% 23 / 55 CC 8 SCAR 38.8
CC
8
Cov
40%
_build_output_handle
72.0
BEGIN
1.0
BEGIN
1.0
CRAP 48.3
↑ Summary Cmd/SpecifiedEntries.pm »
1 #!/usr/bin/perl
2  
3 package KiokuDB::Cmd::OutputHandle;
4 1 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use MooseX::Types::Path::Class qw(File);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 ▶use namespace::clean -except => 'meta';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 excludes qw(KiokuDB::Cmd::InputHandle);
12  
13 1 has file => (
14 traits => [qw(Getopt)],
15 isa => File,
16 is => "ro",
17 coerce => 1,
18 cmd_aliases => "o",
19 documentation => "output file (defaults to STDOUT)",
20 );
21  
22 1 has force => (
23 traits => [qw(Getopt)],
24 isa => "Bool",
25 is => "ro",
26 cmd_aliases => "F",
27 documentation => "allow overwriting of files",
28 );
29  
30 1 has backup => (
31 traits => [qw(Getopt)],
32 isa => "Bool",
33 is => "ro",
34 cmd_aliases => "b",
35 documentation => "rename file before writing",
36 );
37  
38 1 has backup_ext => (
39 traits => [qw(Getopt)],
40 isa => "Str",
41 is => "ro",
42 default => ".bak",
43 cmd_aliases => "B",
44 documentation => "backup extension (defaults to .bak)",
45 );
46  
47 1 has output_handle => (
48 traits => [qw(NoGetopt)],
49 isa => "FileHandle",
50 is => "ro",
51 lazy_build => 1,
52 );
53  
54 0 ▶sub _build_output_handle {
Subroutine _build_output_handle: not called CC=8 SCAR=42.8
55 0 my $self = shift;
56  
57 0 ▶ if ( my $file = $self->file ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $file = $self->file) { } 0 0 0
58 0 ▶ if ( -e $file ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $file) 0 0 0
59 0 ▶ if ( $self->backup ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->backup) { } 0 0 0
elsif (not $self->force) { } 0 0 0
60 0 my $backup = $file . $self->backup_ext;
61  
62 0 ▶ if ( -e $backup && !$self->force ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $backup and not $self->force) 0 0 0
Condition0%0/3
-e $backup and not $self->force
!ll&&!rl&&r
000
MC/DC0%0/2
-e $backup and not $self->force
-e $backup not $self->force
Truth table0%0/3
A and not(B)
A= -e $backupB= not $self->force
ABresult
0X0
100
111
63 0 croak "backup file $backup exists but --force not specified";
64 }
65  
66 0 $self->v("backing up $file to $backup\n");
67  
68 0 ▶ unless ( rename $file, $backup ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (rename $file, $backup) 0 0 0
69 0 croak "renaming of $file to $backup failed"
70 }
71 } elsif ( !$self->force ) {
72 0 croak "$file exists but neither --force nor --backup is specified";
73 }
74 }
75  
76 0 $self->v("opening $file for writing\n");
77  
78 0 return $file->openw;
79 } else {
80 0 return \*STDOUT;
81 }
82 }
83  
84 1 __PACKAGE__
85  
86 __END__
↑ Summary Cmd/SpecifiedEntries.pm »