blib/script/stag-view.pl untested

filter: Statementstmt 0.0% 0 / 50 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 0.0% 0 / 7 Podpod n/a totaltotal 0.0% 0 / 66 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 #!/usr/local/bin/perl -w
2  
3 # POD docs at end
4  
5 use strict;
6  
7 use Data::Stag qw(:all);
8 use Getopt::Long;
9  
10 use FileHandle;
11 use Tk;
12 use Tk::Tree;
13 use Tk::Label;
14  
15 my $sep = "\t";
16 my $parser;
17 my $help;
18 GetOptions(
19 "parser|format|p=s" => \$parser,
20 "help|h"=>\$help,
21 );
22 if ($help) {
23 system("perldoc $0");
24 exit 0;
25 }
26  
27  
28 my $fn = shift @ARGV;
29 my $fh;
30 if ($fn eq '-') {
31 $fh = \*STDIN;
32 }
33 else {
34 $fh = FileHandle->new($fn) || die $fn;
35 }
36 my $stag = Data::Stag->parse(-file=>$fn, -format=>$parser);
37 my @list = $stag->dlist;
38 #print join("\n", @list), "\n";
39  
40 # Create a new main window.
41 #
42 my $top = new MainWindow( -title => "Tree" );
43  
44 # stolen from DBIx::Tree
45 my $tree = $top->Scrolled( 'Tree',
46 -separator => '/',
47 -exportselection => 1,
48 -scrollbars => 'oe',
49 -height => 40,
50 -width => -1);
51 # Pack the tree.
52 #
53 $tree->pack( -expand => 'yes',
54 -fill => 'both',
55 -padx => 10,
56 -pady => 10,
57 -side => 'top' );
58  
59 # When we ran $dbtree->tree earlier, the @list array was populated.
60 # It doesn't have a top element, so we need to pre-pend one to the
61 # list ('/' below).
62 #
63 unshift(@list, '/');
64 foreach ( @list ) {
65  
66 my $text = (split( /[^\\]\//, $_ ))[-1];
67  
68 # If we're on /, let's make its label blank.
69 #
70 if ($_ eq '/') {
71 $text = "";
72 }
73 $text =~ s[\\\/][\/]g;
74 s[\\\/][\\]g;
75  
76 # Add the item (in $_) with $text as the label.
77 #
78
79 # print "ADD $_ $text\n";
80 $text =~ s/\[\d+\]$//;
81 $tree->add( $_, -text => $text );
82
83 }
84  
85 $tree->autosetmode();
86 MainLoop;
87 exit 0;
88  
89 __END__