lib/Pod/Perldoc/ToTk.pm untested

filter: Statementstmt 0.0% 0 / 69 Branchbran 0.0% 0 / 22 Conditioncond 0.0% 0 / 15 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 0.0% 0 / 21 Podpod 0.0% 0 / 12 totaltotal 0.0% 0 / 149 CC 12 SCAR 38.5
CC
12
Cov
0%
parse_from_file
132.0
BEGIN
6.0
is_pageable
2.0
CRAP 46.9
1 package Pod::Perldoc::ToTk;
2 use strict;
3 use warnings;
4  
5 use vars qw($VERSION);
6 $VERSION = '3.28';
7  
8 use parent qw(Pod::Perldoc::BaseTo);
9  
10 sub is_pageable { 1 }
11 sub write_with_binmode { 0 }
12 sub output_extension { 'txt' } # doesn't matter
13 sub if_zero_length { } # because it will be 0-length!
14 sub new { return bless {}, ref($_[0]) || $_[0] }
15  
16 # TODO: document these and their meanings...
17 sub tree { shift->_perldoc_elem('tree' , @_) }
18 sub tk_opt { shift->_perldoc_elem('tk_opt' , @_) }
19 sub forky { shift->_perldoc_elem('forky' , @_) }
20  
21 use Pod::Perldoc ();
22 use File::Spec::Functions qw(catfile);
23  
24 BEGIN{ # Tk is not core, but this is
25 eval { require Tk } ||
26 __PACKAGE__->die( <<"HERE" );
27 You must have the Tk module to use Pod::Perldoc::ToTk.
28 If you have it installed, ensure it's in your Perl library
29 path.
30 HERE
31  
32 __PACKAGE__->die(
33 __PACKAGE__,
34 " doesn't work nice with Tk.pm version $Tk::VERSION"
35 ) if $Tk::VERSION eq '800.003';
36 }
37  
38  
39 BEGIN { eval { require Tk::FcyEntry; }; };
40 BEGIN{ # Tk::Pod is not core, but this is
41 eval { require Tk::Pod } ||
42 __PACKAGE__->die( <<"HERE" );
43 You must have the Tk::Pod module to use Pod::Perldoc::ToTk.
44 If you have it installed, ensure it's in your Perl library
45 path.
46 HERE
47 }
48  
49 # The following was adapted from "tkpod" in the Tk-Pod dist.
50  
51 sub parse_from_file {
52  
53 my($self, $Input_File) = @_;
54 if($self->{'forky'}) {
55 return if fork; # i.e., parent process returns
56 }
57  
58 $Input_File =~ s{\\}{/}g
59 if $self->is_mswin32 or $self->is_dos
60 # and maybe OS/2
61 ;
62  
63 my($tk_opt, $tree);
64 $tree = $self->{'tree' };
65 $tk_opt = $self->{'tk_opt'};
66  
67 #require Tk::ErrorDialog;
68  
69 # Add 'Tk' subdirectories to search path so, e.g.,
70 # 'Scrolled' will find doc in 'Tk/Scrolled'
71  
72 if( $tk_opt ) {
73 push @INC, grep -d $_, map catfile($_,'Tk'), @INC;
74 }
75  
76 my $mw = MainWindow->new();
77 #eval 'use blib "/home/e/eserte/src/perl/Tk-App";require Tk::App::Debug';
78 $mw->withdraw;
79  
80 # CDE use Font Settings if available
81 my $ufont = $mw->optionGet('userFont','UserFont'); # fixed width
82 my $sfont = $mw->optionGet('systemFont','SystemFont'); # proportional
83 if (defined($ufont) and defined($sfont)) {
84 foreach ($ufont, $sfont) { s/:$//; };
85 $mw->optionAdd('*Font', $sfont);
86 $mw->optionAdd('*Entry.Font', $ufont);
87 $mw->optionAdd('*Text.Font', $ufont);
88 }
89  
90 $mw->optionAdd('*Menu.tearOff', $Tk::platform ne 'MSWin32' ? 1 : 0);
91  
92 $mw->Pod(
93 '-file' => $Input_File,
94 (($Tk::Pod::VERSION >= 4) ? ('-tree' => $tree) : ())
95 )->focusNext;
96  
97 # xxx dirty but it works. A simple $mw->destroy if $mw->children
98 # does not work because Tk::ErrorDialogs could be created.
99 # (they are withdrawn after Ok instead of destory'ed I guess)
100  
101 if ($mw->children) {
102 $mw->repeat(1000, sub {
103 # ErrorDialog is withdrawn not deleted :-(
104 foreach ($mw->children) {
105 return if "$_" =~ /^Tk::Pod/ # ->isa('Tk::Pod')
106 }
107 $mw->destroy;
108 });
109 } else {
110 $mw->destroy;
111 }
112 #$mw->WidgetDump;
113 MainLoop();
114  
115 exit if $self->{'forky'}; # we were the child! so exit now!
116 return;
117 }
118  
119 1;
120 __END__