Sling/Print.pm

filter: Statementstmt 97.1% 68 / 70 Branchbran 66.6% 20 / 30 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 13 / 13 Podpod 83.3% 5 / 6 totaltotal 89.0% 106 / 119 CC 16 SCAR 13.8
CC
16
Cov
88%
print_lock
7.0
print_file_lock
6.7
print_result
3.0
CRAP 4.0
« Sling/Request.pm ↑ Summary Sling/AuthzUtil.pm »
1 #!/usr/bin/perl -w
2  
3 package Apache::Sling::Print;
4  
5 11 ▶use 5.008001;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 11 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 11 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 11 ▶use Fcntl ':flock';
Subroutine BEGIN: called CC=1 SCAR=0.0
10 11 ▶use File::Temp;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 11 require Exporter;
13  
14 11 ▶use base qw(Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 11 our @EXPORT_OK = ();
17  
18 11 our $VERSION = '0.27';
19  
20 #{{{sub print_with_lock
21  
22 5 ▶sub print_with_lock {
Subroutine print_with_lock: called CC=2 SCAR=6.9
Pod documented
23 5 my ( $message, $file ) = @_;
24 5 ▶ if ( defined $file ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $file) { } 2 3 5
25 2 return print_file_lock( "$message", $file );
26 }
27 else {
28 3 return print_lock("$message");
29 }
30 }
31  
32 #}}}
33  
34 #{{{sub print_file_lock
35  
36 3 ▶sub print_file_lock {
Subroutine print_file_lock: called CC=6 SCAR=19.0
Pod documented
37 3 my ( $message, $file ) = @_;
38 3 ▶ if ( open my $out, '>>', $file ) {
Branch: 1 branch
BranchTrueFalseTotal
if (open my $out, '>>', $file) { } 3 0 3
39 3 ▶ flock $out, LOCK_EX or croak q{Unable to obtain exclusive lock};
Branch: 1 branch
BranchTrueFalseTotal
flock $out, 2 or croak("Unable to obtain exclusive lock") 2 1 3
40 2 ▶ print {$out} $message . "\n" or croak q{Problem printing!};
Branch: 1 branch
BranchTrueFalseTotal
print {$out;} $message . "\n" or croak("Problem printing!") 2 0 2
41 2 ▶ flock $out, LOCK_UN or croak q{Problem releasing exclusive lock};
Branch: 1 branch
BranchTrueFalseTotal
flock $out, 8 or croak("Problem releasing exclusive lock") 2 0 2
42 2 ▶ close $out or croak q{Problem closing!};
Branch: 1 branch
BranchTrueFalseTotal
close $out or croak("Problem closing!") 2 0 2
43 }
44 else {
45 0 croak "Could not open file: $file";
46 }
47 2 return 1;
48 }
49  
50 #}}}
51  
52 #{{{sub print_lock
53  
54 4 ▶sub print_lock {
Subroutine print_lock: called CC=6 SCAR=19.4
Pod documented
55 4 my ($message) = @_;
56 4 my ( $tmp_print_file_handle, $tmp_print_file_name ) =
57 File::Temp::tempfile();
58 4 ▶ if ( open my $lock, '>>', $tmp_print_file_name ) {
Branch: 1 branch
BranchTrueFalseTotal
if (open my $lock, '>>', $tmp_print_file_name) { } 4 0 4
59 4 ▶ flock $lock, LOCK_EX or croak q{Unable to obtain exclusive lock};
Branch: 1 branch
BranchTrueFalseTotal
flock $lock, 2 or croak("Unable to obtain exclusive lock") 4 0 4
60 4 ▶ print $message . "\n" or croak q{Problem printing!};
Branch: 1 branch
BranchTrueFalseTotal
print $message . "\n" or croak("Problem printing!") 4 0 4
61 4 ▶ flock $lock, LOCK_UN or croak q{Problem releasing exclusive lock};
Branch: 1 branch
BranchTrueFalseTotal
flock $lock, 8 or croak("Problem releasing exclusive lock") 4 0 4
62 4 ▶ close $lock or croak q{Problem closing!};
Branch: 1 branch
BranchTrueFalseTotal
close $lock or croak("Problem closing!") 4 0 4
63 4 unlink($tmp_print_file_name);
64 }
65 else {
66 0 croak q(Could not open lock on temporary file!);
67 }
68 4 return 1;
69 }
70  
71 #}}}
72  
73 #{{{sub print_result
74  
75 2 ▶sub print_result {
Subroutine print_result: called CC=3 SCAR=11.0
Pod documented
76 2 my ($object) = @_;
77 2 my $message = $object->{'Message'};
78 2 ▶ if ( $object->{'Verbose'} >= 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($object->{"Verbose"} >= 1) 2 0 2
79 2 $message .= "\n**** Status line was: ";
80 2 $message .= ${ $object->{'Response'} }->status_line;
81 2 ▶ if ( $object->{'Verbose'} >= 3 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($object->{"Verbose"} >= 3) 1 1 2
82 1 $message .= "\n**** Full Content of Response was: \n";
83 1 $message .= ${ $object->{'Response'} }->content;
84 }
85 }
86 2 print_with_lock( $message, $object->{'Log'} );
87 2 return 1;
88 }
89  
90 #}}}
91  
92 #{{{sub date_string
93  
94 3 ▶sub date_string {
Subroutine date_string: called CC=3 SCAR=11.0
Pod undocumented
95 3 my ( $day_of_week, $month, $year_offset, $day_of_month, $hour, $minute,
96 $sec )
97 = @_;
98 3 my @months = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
99 3 my @week_days = qw(Sun Mon Tue Wed Thu Fri Sat Sun);
100 3 ▶ if ( $sec =~ /^[0-9]$/msx ) { $sec = "0$sec"; }
Branch: 1 branch
BranchTrueFalseTotal
if ($sec =~ /^[0-9]$/msx) 1 2 3
101 3 ▶ if ( $minute =~ /^[0-9]$/msx ) { $minute = "0$minute"; }
Branch: 1 branch
BranchTrueFalseTotal
if ($minute =~ /^[0-9]$/msx) 1 2 3
102 3 my $year = 1900 + $year_offset;
103 return
104 3 "$week_days[$day_of_week] $months[$month] $day_of_month $hour:$minute:$sec";
105 }
106  
107 #}}}
108  
109 #{{{sub date_time
110  
111 1 ▶sub date_time {
Subroutine date_time: called CC=1 SCAR=0.0
Pod documented
112 (
113 1 my $sec,
114 my $minute,
115 my $hour,
116 my $day_of_month,
117 my $month,
118 my $year_offset,
119 my $day_of_week,
120 my $day_of_year,
121 my $daylight_savings
122 ) = localtime;
123 1 return date_string( $day_of_week, $month, $year_offset, $day_of_month,
124 $hour, $minute, $sec );
125 }
126  
127 #}}}
128  
129 11 1;
130  
131 __END__
« Sling/Request.pm ↑ Summary Sling/AuthzUtil.pm »