Indexer/Dispatcher/Serial.pm

filter: Statementstmt 34.3% 22 / 64 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 61.5% 8 / 13 Podpod 100% 2 / 2 totaltotal 39.5% 32 / 81 CC 5 SCAR 13.1
CC
5
Cov
33%
_make_interface_callback
10.0
_elapsed
6.0
__ANON__
4.6
CRAP 3.7
« Indexer/Queue/ErrorReports.pm ↑ Summary Indexer/Notes.pm »
1 package MyCPAN::Indexer::Dispatcher::Serial;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 1 ▶use parent qw(MyCPAN::Indexer::Component);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use vars qw($VERSION $logger);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 $VERSION = '1.282';
8  
9 1 ▶use Log::Log4perl;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 $logger = Log::Log4perl->get_logger( 'Dispatcher' );
13 }
14  
15 =encoding utf8
16  
17 =head1 NAME
18  
19 MyCPAN::Indexer::Dispatcher::Serial - Pass out work in the same process
20  
21 =head1 SYNOPSIS
22  
23 Use this in C<backpan_indexer.pl> by specifying it as the queue class:
24  
25 # in backpan_indexer.config
26 dispatch_class MyCPAN::Indexer::Dispatcher::Serial
27  
28 =head1 DESCRIPTION
29  
30 This class takes the list of distributions to process and passes them
31 out to the code that will do the work.
32  
33 =head2 Methods
34  
35 =over 4
36  
37 =item component_type
38  
39 This is the dispatcher type.
40  
41 =cut
42  
43 0 ▶sub component_type { $_[0]->dispatcher_type }
Subroutine component_type: not called CC=1 SCAR=6.9
Pod documented
44  
45 =item get_dispatcher
46  
47 Adds the C<dispatcher> key with a code reference.
48  
49 =cut
50  
51 sub get_dispatcher
52 0 ▶ {
Subroutine get_dispatcher: not called CC=1 SCAR=6.9
Pod documented
53 0 my( $self ) = @_;
54  
55 0 $self->get_coordinator->set_note(
56 'interface_callback',
57 $self->_make_interface_callback,
58 )
59 }
60  
61 sub _make_interface_callback
62 0 ▶ {
Subroutine _make_interface_callback: not called CC=3 SCAR=23.0
63 0 my( $self ) = @_;
64  
65 0 my $Notes = {};
66  
67 0 $Notes->{$_} = [] foreach qw(PID recent errors );
68  
69 0 $Notes->{Total} = scalar @{ $self->get_note( 'queue' ) };
70 0 $Notes->{Left} = $Notes->{Total};
71 0 $Notes->{Errors} = 0;
72 0 $Notes->{Done} = 0;
73 0 $Notes->{Started} = scalar localtime;
74 0 $Notes->{Finished} = 0;
75  
76 0 $Notes->{queue_cursor} = 0;
77  
78 0 foreach my $key ( keys %$Notes )
79 {
80 0 $self->set_note( $key, $Notes->{$key} );
81 }
82  
83 0 ▶ $Notes->{interface_callback} = sub {
Subroutine __ANON__: not called CC=2 SCAR=15.3
84 0 $logger->debug( "Start: Finished: $Notes->{Finished} Left: $Notes->{Left}" );
85  
86 0 ▶ unless( $self->get_note('Left') )
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->get_note("Left")) 0 0 0
87 {
88 0 $self->set_note('Finished', 'true' );
89 0 return;
90 };
91  
92 0 $self->set_note_unless_defined('_started', time);
93  
94 0 $self->set_note('_elapsed', time - $self->get_note('_started') );
95 0 $self->set_note('Elapsed', _elapsed( $self->get_note('_elapsed') ) );
96  
97 0 my $item = ${ $self->get_note('queue') }[ $self->get_note('queue_cursor') ];
98 0 $self->increment_note( 'queue_cursor' );
99  
100 0 $self->increment_note( 'Done' );
101 0 $self->set_note('Left', $self->get_note('Total') - $self->get_note('Done') );
102 $logger->debug(
103 sprintf "Total: %s Done: %s Left: %s Finished: %s",
104 0 map { $self->get_note( $_ ) } qw(Total Done Left Finished)
105 );
106  
107 1 ▶ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
108 $self->set_note('Rate', sprintf "%.2f / sec ",
109 0 eval { $self->get_note('Done') / $self->get_note('_elapsed') }
110 );
111  
112 0 my $info = $self->get_note('child_task')->( $item );
113  
114 0 $info;
115 0 };
116  
117 }
118  
119 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
120 1 my %hash = ( days => 864000, hours => 3600, minutes => 60 );
121  
122 sub _elapsed
123 0 ▶ {
Subroutine _elapsed: not called CC=2 SCAR=17.9
124 0 my $seconds = shift;
125  
126 0 my @v;
127 0 foreach my $key ( qw(days hours minutes) )
128 {
129 0 push @v, int( $seconds / $hash{$key} );
130 0 $seconds -= $v[-1] * $hash{$key}
131 }
132  
133 0 push @v, $seconds;
134  
135 0 sprintf "%dd %02dh %02dm %02ds", @v;
136 }
137 }
138  
139 1 1;
140  
141 =back
142  
143 =head1 SEE ALSO
144  
145 MyCPAN::Indexer, MyCPAN::Indexer::Tutorial
146  
147 =head1 SOURCE AVAILABILITY
148  
149 This code is in Github:
150  
151 git://github.com/briandfoy/mycpan-indexer.git
152  
153 =head1 AUTHOR
154  
155 brian d foy, C<< <bdfoy@cpan.org> >>
156  
157 =head1 COPYRIGHT AND LICENSE
158  
159 Copyright © 2010-2018, brian d foy <bdfoy@cpan.org>. All rights reserved.
160  
161 You may redistribute this under the terms of the Artistic License 2.0.
162  
163 =cut
164  
« Indexer/Queue/ErrorReports.pm ↑ Summary Indexer/Notes.pm »