File Coverage

blib/lib/CGI/Widget/HList.pm
Criterion Covered Total %
statement 4 6 66.6
branch n/a
condition n/a
subroutine 2 2 100.0
pod n/a
total 6 8 75.0


line stmt bran cond sub pod time code
1             package CGI::Widget::HList;
2              
3 1     1   7640 use lib '../blib/lib';
  1         2  
  1         6  
4 1     1   1547 use Tree::DAG_Node;
  0            
  0            
5             use CGI qw(img br);
6             use CGI::Widget;
7             use CGI::Widget::HList::Node;
8             use vars qw(@ISA $VERSION);
9             use strict;
10             use overload '""' => \&ashtml;
11              
12             @ISA = qw(CGI::Widget);
13             $VERSION = '0.53';
14              
15             sub _init {
16             my $self = shift;
17              
18             #clean out leading -'s;
19             my @t = @_;
20             for(my $i = 0; $i < @t; $i+=2){ $t[$i] =~ s/^-//; }
21             my %param = @t;
22              
23             $self->img_open( $param{img_open} || img({-src=>'../images/menu_open.gif',-border=>0})); #-
24             $self->img_close( $param{img_close} || img({-src=>'../images/menu_close.gif',-border=>0})); #+
25             $self->img_leaf( $param{img_leaf} || img({-src=>'../images/menu_leaf.gif',-border=>0})); #O
26             $self->img_spacer($param{img_spacer} || img({-src=>'../images/menu_space.gif',-border=>0})); #_
27             $self->img_trunk( $param{img_trunk} || img({-src=>'../images/menu_trunk.gif',-border=>0})); #|
28             $self->img_branch($param{img_branch} || img({-src=>'../images/menu_branch.gif',-border=>0}));#=
29             $self->img_corner($param{img_corner} || img({-src=>'../images/menu_corner.gif',-border=>0}));#L
30              
31             #open, close, and leaf are all a type of node
32             $self->render_node( $param{render_node} ||
33             sub{
34             my $node = shift;
35             $node->pregnant ? return $self->img_close :
36             $node->state ?
37             $node->daughters ? return $self->img_open
38             : return $self->img_leaf :
39             $node->daughters ? return $self->img_close :
40             return $self->img_leaf ;
41             }
42             );
43              
44             #while these are of unique types
45             $self->render_spacer($param{render_spacer} || sub{return $self->img_spacer});
46             $self->render_trunk( $param{render_trunk} || sub{return $self->img_trunk});
47             $self->render_branch($param{render_branch} ||
48             sub{
49             my $node = shift;
50             $node->right_sister ? return $self->img_branch
51             : return $self->img_corner;
52             }
53             );
54              
55             $param{root} ? $self->root_node($param{root}) : $self->_init_root_node();
56             return 1;
57             }
58              
59             sub root_node {
60             my($self,$val) = @_;
61             return $self->{root} unless defined $val;
62             $self->{root} = $val;
63             return $self->{root};
64             }
65              
66             sub _init_root_node {
67             my $self = shift;
68             my $node = $self->node;
69             my $root = $self->root_node($node) || die "$node root creation failed: $!";
70             return $self->root_node;
71             }
72              
73             sub node {
74             my $self = shift;
75             my $node = CGI::Widget::HList::Node->new or die "$!";
76             return $node;
77             }
78              
79             sub html {
80             my ($self,@args) = @_;
81             $self = __PACKAGE__->new(@args) unless ref $self;
82             return $self->ashtml(@_);
83             }
84              
85             sub ashtml {
86             my $self = shift;
87             my @returns = $self->root_node->dump_names(trunk => $self->render_trunk,
88             node => $self->render_node,
89             spacer => $self->render_spacer,
90             branch => $self->render_branch,
91             break => br."\n",
92             );
93             return join '',@returns;
94             }
95              
96             sub render_node {
97             my($self,$val) = @_;
98             return $self->{render_node} unless defined $val;
99             $self->{render_node} = $val;
100             return $self->{render_node};
101             }
102              
103             sub render_spacer {
104             my($self,$val) = @_;
105             return $self->{render_spacer} unless defined $val;
106             $self->{render_spacer} = $val;
107             return $self->{render_spacer};
108             }
109              
110             sub render_trunk {
111             my($self,$val) = @_;
112             return $self->{render_trunk} unless defined $val;
113             $self->{render_trunk} = $val;
114             return $self->{render_trunk};
115             }
116              
117             sub render_branch {
118             my($self,$val) = @_;
119             return $self->{render_branch} unless defined $val;
120             $self->{render_branch} = $val;
121             return $self->{render_branch};
122             }
123              
124             sub img_open {
125             my($self,$val) = @_;
126             return $self->{img_open} unless defined $val;
127             $self->{img_open} = $val;
128             return $self->{img_open};
129             }
130              
131             sub img_close {
132             my($self,$val) = @_;
133             return $self->{img_close} unless defined $val;
134             $self->{img_close} = $val;
135             return $self->{img_close};
136             }
137              
138             sub img_leaf {
139             my($self,$val) = @_;
140             return $self->{img_leaf} unless defined $val;
141             $self->{img_leaf} = $val;
142             return $self->{img_leaf};
143             }
144              
145             sub img_spacer {
146             my($self,$val) = @_;
147             return $self->{img_spacer} unless defined $val;
148             $self->{img_spacer} = $val;
149             return $self->{img_spacer};
150             }
151              
152             sub img_trunk {
153             my($self,$val) = @_;
154             return $self->{img_trunk} unless defined $val;
155             $self->{img_trunk} = $val;
156             return $self->{img_trunk};
157             }
158              
159             sub img_branch {
160             my($self,$val) = @_;
161             return $self->{img_branch} unless defined $val;
162             $self->{img_branch} = $val;
163             return $self->{img_branch};
164             }
165              
166             sub img_corner {
167             my($self,$val) = @_;
168             return $self->{img_corner} unless defined $val;
169             $self->{img_corner} = $val;
170             return $self->{img_corner};
171             }
172              
173             1;
174             __END__