blib/lib/Test/Smoke/PostQueue.pm

filter: Statementstmt 84.4% 98 / 116 Branchbran 57.5% 23 / 40 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 13 / 13 Podpod 100% 4 / 4 totaltotal 78.0% 139 / 178 CC 30 SCAR 20.4
CC
30
Cov
77%
new
11.6
add
9.4
purge
8.8
CRAP 7.7
« blib/lib/Test/Smoke/Syncer/Hardlink.pm ↑ Summary blib/lib/Test/Smoke/BuildCFG.pm »
1 package Test::Smoke::PostQueue;
2 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 6 our $VERSION = '0.001';
6  
7 6 ▶use base 'Test::Smoke::ObjectBase';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 6 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 6 ▶use Cwd qw< abs_path >;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 6 ▶use Fcntl qw< :flock SEEK_SET >;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 6 ▶use File::Spec::Functions qw< catfile file_name_is_absolute >;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 6 ▶use Test::Smoke::LogMixin;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 =head1 NAME
16  
17 Test::Smoke::PostQueue - Queue mechanism for re-posting reports.
18  
19 =head1 SYNOPSIS
20  
21 use Test::Smoke::PostQueue;
22 my $queue = Test::Smoke::PostQueue->new(
23 qfile => $qfile,
24 adir => $adir,
25 poster => $poster
26 );
27  
28 $queue->add($patch);
29  
30 $queue->handle_queue();
31  
32 =head1 DESCRIPTION
33  
34 This is implemented as a singleton.
35  
36 It can only work if archiving is true.
37  
38 =cut
39  
40 6 my $_singleton;
41 6 my %CONFIG = (
42 df_qfile => undef,
43 df_adir => undef,
44 df_poster => undef,
45 df_v => 0,
46  
47 general_options => [qw< qfile adir poster v >],
48 );
49  
50 =head2 Test::Smoke::PostQueue->new(%arguments)
51  
52 Returns an instantiated object, if it was already created, return that one.
53  
54 =head3 Arguments
55  
56 Named, list:
57  
58 =over
59  
60 =item B<qfile>
61  
62 The file we keep the queue in (one patchlevel per line)
63  
64 =item B<adir>
65  
66 The archive directory to get the report (jsn) from.
67  
68 =item B<poster>
69  
70 This must be an instance of L<Test::Smoke::Poster> with C<ddir> set to C<adir>.
71  
72 =item B<v>
73  
74 Verbosity.
75  
76 =back
77  
78 =cut
79  
80 5 ▶sub new {
Subroutine new: called CC=10 SCAR=24.5
Pod documented
81 5 my $class = shift;
82  
83 5 ▶ return $_singleton if defined($_singleton);
Branch: 1 branch
BranchTrueFalseTotal
if defined $_singleton 2 3 5
84  
85 0 ▶ my %args = ref $_[0] eq 'HASH' ? %{$_[0]} : @_;
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'HASH' ? : 0 3 3
86  
87 my %fields = map {
88 12 ▶ my $value = exists $args{$_} ? $args{ $_ } : $CONFIG{ "df_$_" };
Branch: 1 branch
BranchTrueFalseTotal
exists $args{$_} ? : 12 0 12
89 12 ( $_ => $value )
90 3 } @{ $CONFIG{general_options} };
91 3 for my $fld (qw< qfile adir >) {
92 die __PACKAGE__ . " must have $fld as defined attribute in new()!\n"
93 6 ▶ if !defined($fields{$fld});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $fields{$fld} 0 6 6
94 }
95 die __PACKAGE__ . " must have $_ as a Test::Smoke::Poster in new!\n"
96 unless defined($fields{poster})
97 3 ▶ && UNIVERSAL::isa($fields{poster}, 'Test::Smoke::Poster::Base');
Branch: 1 branch
BranchTrueFalseTotal
unless defined $fields{"poster"} and UNIVERSAL::isa($fields{"poster"}, "Test::Smoke::Poster::Base") 0 3 3
Condition33%1/3
defined $fields{"poster"} and UNIVERSAL::isa($fields{"poster"}, "Test::Smoke::Poster::Base")
!ll&&!rl&&r
003
MC/DC0%0/2
defined $fields{"poster"} and UNIVERSAL::isa($fields{"poster"}, "Test::Smoke::Poster::Base")
defined $fields{"poster"} UNIVERSAL::isa($fields{"poster"}, "Test::Smoke::Poster::Base")
Truth table33%1/3
A and B
A= defined $fields{"poster"}B= UNIVERSAL::isa($fields{"poster"}, "Test::Smoke::Poster::Base")
ABresult
0X0
100
111
98  
99 3 _make_absolute($_) for @fields{qw< qfile adir >};
100  
101 3 $fields{ "_$_" } = delete($fields{$_}) for qw< qfile adir poster v >;
102 3 $_singleton = bless(\%fields, $class);
103 3 return $_singleton;
104 }
105  
106 =head2 $queue->add($patchlevel)
107  
108 Adds an item to the queue-file.
109  
110 =cut
111  
112 1 ▶sub add {
Subroutine add: called CC=7 SCAR=22.4
Pod documented
113 1 my $self = shift;
114 1 my ($patchlevel) = @_;
115  
116 1 ▶ if (! -e $self->qfile) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-e $self->qfile) 1 0 1
117 0 ▶ open(my $chk, '>', $self->qfile) or confess("Cannot create(@{[$self->qfile]}: $!");
Branch: 1 branch
BranchTrueFalseTotal
open my $chk, ">", $self->qfile or confess("Cannot create(@{[$self->qfile];}: $!") 1 0 1
118 }
119 1 ▶ open(my $fh, '+<', $self->qfile) or do {
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "+<", $self->qfile or do { $self->log_warn("Cannot open(@{[$self->qfile];}, r/w): $!"); return 0 } 1 0 1
120 0 $self->log_warn("Cannot open(@{[$self->qfile]}, r/w): $!");
121 0 return 0;
122 };
123  
124 0 ▶ flock($fh, LOCK_EX) or confess("Cannot flock(@{[$self->qfile]}): $!");
Branch: 1 branch
BranchTrueFalseTotal
flock $fh, 2 or confess("Cannot flock(@{[$self->qfile];}): $!") 1 0 1
125 1 chomp(my @q = <$fh>);
126 1 seek($fh, 0, SEEK_SET);
127 1 truncate($fh, 0);
128 0 my %q = map { ($_ => undef) } @q;
129 1 $q{$patchlevel}++;
130 1 print {$fh} "$_\n" for keys %q;
131 0 ▶ flock($fh, LOCK_UN) or confess("Cannot unflock(@{[$self->qfile]}: $!");
Branch: 1 branch
BranchTrueFalseTotal
flock $fh, 8 or confess("Cannot unflock(@{[$self->qfile];}: $!") 1 0 1
132 1 close($fh);
133 1 return 1;
134 }
135  
136 =head2 $queue->handle()
137  
138 This reads the queue-file and tries to post every report it can find in the
139 archive.
140  
141 =cut
142  
143 3 ▶sub handle {
Subroutine handle: called CC=8 SCAR=21.2
Pod documented
144 3 my $self = shift;
145 3 ▶ open(my $fh, '+<', $self->qfile) or do {
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "+<", $self->qfile or do { $self->log_warn("Cannot read queuefile: $!"); return } 3 0 3
146 0 $self->log_warn("Cannot read queuefile: $!");
147 0 return;
148 };
149  
150 0 ▶ flock($fh, LOCK_EX) or confess("Cannot flock(@{[$self->qfile]}): $!");
Branch: 1 branch
BranchTrueFalseTotal
flock $fh, 2 or confess("Cannot flock(@{[$self->qfile];}): $!") 3 0 3
151 3 chomp(my @q = <$fh>);
152 3 my @left;
153 3 my $orig_ddir = $self->poster->ddir;
154 3 $self->poster->ddir($self->adir);
155 3 my $orig_jsnfile = $self->poster->jsnfile;
156 3 for my $patch (@q) {
157 8 my $jsnfile = sprintf("jsn%s.jsn", $patch);
158 8 $self->poster->jsnfile($jsnfile);
159  
160 8 my $id;
161 8 ▶ eval { $id = $self->poster->post($jsnfile); 1; } or push @left, $patch;
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $id = $self->poster->post($jsnfile); 1 } } or push @left, $patch 7 1 8
162 8 ▶ $self->log_warn("Posted $patch from queue: report_id = $id") if $id;
Branch: 1 branch
BranchTrueFalseTotal
if $id 6 2 8
163 }
164 3 $self->poster->ddir($orig_ddir);
165 3 $self->poster->jsnfile($orig_jsnfile);
166  
167 3 seek($fh, 0, SEEK_SET);
168 3 truncate($fh, 0);
169 3 print {$fh} "$_\n" for @left;
170 0 ▶ flock($fh, LOCK_UN) or confess("Cannot unflock(@{[$self->qfile]}: $!");
Branch: 1 branch
BranchTrueFalseTotal
flock $fh, 8 or confess("Cannot unflock(@{[$self->qfile];}: $!") 3 0 3
171 3 close($fh);
172 3 return 1;
173 }
174  
175 =head2 $queue->purge
176  
177 Removes all entries that do not exist in C<adir>.
178  
179 =cut
180  
181 2 ▶sub purge {
Subroutine purge: called CC=7 SCAR=21.8
Pod documented
182 2 my $self = shift;
183 2 ▶ open(my $fh, '+<', $self->qfile) or do {
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "+<", $self->qfile or do { $self->log_warn("Cannot read queuefile: $!"); return } 2 0 2
184 0 $self->log_warn("Cannot read queuefile: $!");
185 0 return;
186 };
187  
188 0 ▶ flock($fh, LOCK_EX) or confess("Cannot flock(@{[$self->qfile]}): $!");
Branch: 1 branch
BranchTrueFalseTotal
flock $fh, 2 or confess("Cannot flock(@{[$self->qfile];}): $!") 2 0 2
189 2 chomp(my @q = <$fh>);
190 2 my @left;
191 2 for my $patch (@q) {
192 1 my $jsnfile = sprintf("jsn%s.jsn", $patch);
193 1 ▶ push(@left, $patch) if -e catfile($self->adir, $jsnfile);
Branch: 1 branch
BranchTrueFalseTotal
if -e catfile($self->adir, $jsnfile) 0 1 1
194 }
195 2 seek($fh, 0, SEEK_SET);
196 2 truncate($fh, 0);
197 0 print {$fh} "$_\n" for @left;
198 0 ▶ flock($fh, LOCK_UN) or confess("Cannot unflock(@{[$self->qfile]}: $!");
Branch: 1 branch
BranchTrueFalseTotal
flock $fh, 8 or confess("Cannot unflock(@{[$self->qfile];}: $!") 2 0 2
199 2 close($fh);
200 2 return 1;
201 }
202  
203 # !NASTY, changes the argument
204 6 ▶sub _make_absolute {
Subroutine _make_absolute: called CC=2 SCAR=9.2
205 6 ▶ return if file_name_is_absolute($_[0]);
Branch: 1 branch
BranchTrueFalseTotal
if file_name_is_absolute($_[0]) 6 0 6
206 0 $_[0] = abs_path($_[0]);
207 }
208  
209 6 1;
210  
211 =head1 COPYRIGHT
212  
213 E<copy> 2002-2013, Abe Timmerman <abeltje@cpan.org> All rights reserved.
214  
215 See L<AUTHORS> for contributers.
216  
217 This library is free software; you can redistribute it and/or modify
218 it under the same terms as Perl itself.
219  
220 See:
221  
222 =over 4
223  
224 =item * L<http://www.perl.com/perl/misc/Artistic.html>
225  
226 =item * L<http://www.gnu.org/copyleft/gpl.html>
227  
228 =back
229  
230 This program is distributed in the hope that it will be useful,
231 but WITHOUT ANY WARRANTY; without even the implied warranty of
232 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
233  
234 =cut
« blib/lib/Test/Smoke/Syncer/Hardlink.pm ↑ Summary blib/lib/Test/Smoke/BuildCFG.pm »