Indexer/Interface/Tk.pm untested

filter: Statementstmt 0.0% 0 / 97 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 0.0% 0 / 17 Podpod 0.0% 0 / 7 totaltotal 0.0% 0 / 126 CC 2 SCAR 8.9
CC
2
Cov
0%
BEGIN
6.0
BEGIN
2.0
component_type
2.0
CRAP 2.4
1 package MyCPAN::Indexer::Interface::Tk;
2 use strict;
3 use warnings;
4  
5 BEGIN {
6 my $rc = eval {
7 require Tk;
8 require Tk::ProgressBar;
9  
10 Tk->import;
11 Tk::ProgressBar->import;
12 1
13 };
14  
15 die "You need to install the Tk and Tk::ProgressBar modules " .
16 " to use MyCPAN::Indexer::Interface::Tk\n" unless $rc;
17 }
18  
19 use base qw(MyCPAN::Indexer::Component);
20 use vars qw($VERSION $logger);
21 $VERSION = '1.282';
22  
23 use Log::Log4perl;
24 use Tk;
25  
26 BEGIN {
27 $logger = Log::Log4perl->get_logger( 'Interface' );
28 }
29  
30 =encoding utf8
31  
32 =head1 NAME
33  
34 MyCPAN::Indexer::Interface::Tk - Index a Perl distribution
35  
36 =head1 SYNOPSIS
37  
38 Use this in backpan_indexer.pl by specifying it as the interface class:
39  
40 # in backpan_indexer.config
41 interface_class MyCPAN::Indexer::Interface::Tk
42  
43 =head1 DESCRIPTION
44  
45 This class presents the information as the indexer runs, using Tk.
46  
47 =head2 Methods
48  
49 =over 4
50  
51 =item component_type
52  
53 This is an interface type
54  
55 =cut
56  
57 sub component_type { $_[0]->interface_type }
58  
59 =item do_interface
60  
61 =cut
62  
63 sub do_interface
64 {
65 my( $self ) = @_;
66  
67 my $config = $self->get_config;
68 use Tk;
69  
70 my $mw = MainWindow->new;
71 $mw->geometry('500x375');
72  
73 $mw->resizable( 0, 0 );
74 $mw->title( join " ", $config->indexer_class, $config->indexer_class->VERSION );
75 my $menubar = _menubar( $mw );
76  
77 my( $progress, $top, $middle, $bottom ) = map {
78 $mw->Frame->pack(
79 -anchor => 'w',
80 -expand => 1,
81 -fill => 'x',
82 );
83 } 1 .. 4;
84  
85 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
86 my $tracker = _make_frame( $top, 'left' );
87  
88 my $tracker_left = $tracker->Frame->pack(
89 -anchor => 'w',
90 -side => 'left',
91 -expand => 1,
92 -fill => 'x',
93 );
94 foreach my $label ( qw( Total Done Left Errors ) )
95 {
96 my $frame = $tracker_left->Frame->pack( -side => 'top' );
97 $frame->Label(
98 -text => $label,
99 -width => 6 )->pack(
100 -side => 'left'
101 );
102 $frame->Entry(
103 -width => 6,
104 -textvariable => \ $Notes->{$label},
105 -relief => 'flat',
106 )->pack(
107 -side => 'right',
108 );
109 }
110  
111 my $tracker_right = $tracker->Frame->pack(
112 -anchor => 'w',
113 -side => 'left',
114 -expand => 1,
115 -fill => 'x',
116 );
117 foreach my $label ( qw( UUID Started Elapsed Rate ) )
118 {
119 $Notes->{$label} ||= ' ' x 60;
120 my $frame = $tracker_right->Frame->pack(
121 -side => 'top',
122 -anchor => 'w',
123 -fill => 'x',
124 );
125 $frame->Label(
126 -text => $label,
127 -width => 6,
128 )->pack(
129 -side => 'left',
130 );
131 $frame->Entry(
132 -textvariable => \ $Notes->{$label},
133 -relief => 'flat',
134 -width => -1,
135 -state => 'disabled',
136 -disabledforeground => '',
137 )->pack(
138 -side => 'right',
139 -expand => 1,
140 -fill => 'x',
141 );
142 }
143  
144 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
145 require Tk::ProgressBar;
146  
147 my $bar = $progress->Frame->pack(
148 -anchor => 'w',
149 -side => 'left',
150 -expand => 1,
151 -fill => 'x'
152 );
153 $bar->ProgressBar(
154 -from => 0,
155 -to => $Notes->{Total},
156 -variable => \ $Notes->{Done},
157 -colors => [ 0, 'green',],
158 -gap => 0,
159 )->pack(
160 -side => 'top',
161 -fill => 'x',
162 );
163  
164 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
165 my @recent = qw( a b c d e );
166 my $jobs = $middle->Frame->pack( -anchor => 'w', -expand => 1, -fill => 'x' );
167  
168 my $count_frame = _make_frame( $jobs, 'left' );
169 $count_frame->Label( -text => '#', -width => 3 )->pack( -side => 'top' );
170 $count_frame->Listbox(
171 -height => $Notes->{Threads},
172 -width => 3,
173 -listvariable => [ 1 .. $Notes->{Threads} ],
174 -relief => 'flat',
175 )->pack(
176 -side => 'bottom'
177 );
178  
179 my $pid_frame = _make_frame( $jobs, 'left' );
180 $pid_frame->Label( -text => 'PID', -width => 6 )->pack( -side => 'top' );
181 $pid_frame->Listbox(
182 -height => $Notes->{Threads},
183 -width => 6,
184 -listvariable => $Notes->{PID},
185 -relief => 'flat',
186 )->pack(
187 -side => 'bottom'
188 );
189  
190 my $proc_frame = $jobs->Frame->pack( -anchor => 'w', -expand => 1, -fill => 'x' );
191 $proc_frame->Label( -text => 'Processing', -width => 35 )->pack( -side => 'top' );
192 $proc_frame->Listbox(
193 -height => $Notes->{Threads},
194 -listvariable => $Notes->{recent},
195 -relief => 'flat',
196 )->pack(
197 -side => 'bottom',
198 -expand => 1,
199 -fill => 'x'
200 );
201  
202 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
203 my @errors = qw( dog bird cat );
204 my $errors = $bottom->Frame->pack( -anchor => 'w', -expand => 1, -fill => 'x' );
205 $errors->Label( -text => 'Errors', )->pack( -side => 'top', -anchor => 'w');
206 $errors->Listbox(
207 -height => 10,
208 -listvariable => $Notes->{errors},
209 -relief => 'flat',
210 )->pack(
211 -expand => 1,
212 -fill => 'x',
213 -side => 'left',
214 -anchor => 'w',
215 );
216  
217  
218 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
219 $mw->repeat( 500, $self->get_note( 'interface_callback' ) );
220  
221 MainLoop;
222 }
223  
224  
225 sub _make_frame
226 {
227 my $mw = shift;
228 my $side = shift;
229  
230 my $frame = $mw->Frame->pack(
231 -anchor => 'n',
232 -side => $side,
233 );
234  
235 return $frame;
236 }
237  
238 sub _menubar
239 {
240 my $mw = shift;
241  
242 $mw->configure( -menu => my $menubar = $mw->Menu );
243 my $file_items = [
244 [qw( command ~Quit -accelerator Ctrl-q -command ) => sub { exit } ]
245 ];
246  
247 my $file = _menu( $menubar, "~File", $file_items );
248 my $edit = _menu( $menubar, "~Edit", [] );
249  
250 return $menubar;
251 }
252  
253 sub _menu
254 {
255 my $menubar = shift;
256 my $title = shift;
257 my $items = shift;
258  
259 my $menu = $menubar->cascade(
260 -label => $title,
261 -menuitems => $items,
262 -tearoff => 0,
263 );
264  
265 return $menu;
266 }
267  
268  
269 =back
270  
271  
272 =head1 SEE ALSO
273  
274 MyCPAN::Indexer
275  
276 =head1 SOURCE AVAILABILITY
277  
278 This code is in Github:
279  
280 git://github.com/briandfoy/mycpan-indexer.git
281  
282 =head1 AUTHOR
283  
284 brian d foy, C<< <bdfoy@cpan.org> >>
285  
286 =head1 COPYRIGHT AND LICENSE
287  
288 Copyright © 2008-2018, brian d foy <bdfoy@cpan.org>. All rights reserved.
289  
290 You may redistribute this under the terms of the Artistic License 2.0.
291  
292 =cut
293  
294 1;