File Coverage

blib/lib/SVG/Graph/Data/Node.pm
Criterion Covered Total %
statement 37 41 90.2
branch 11 16 68.7
condition 5 8 62.5
subroutine 8 9 88.8
pod 6 6 100.0
total 67 80 83.7


line stmt bran cond sub pod time code
1             package SVG::Graph::Data::Node;
2              
3 1     1   6 use strict;
  1         2  
  1         34  
4 1     1   5 use base qw(Tree::DAG_Node);
  1         1  
  1         1623  
5              
6             =head2 new
7              
8             Title : new
9             Usage :
10             Function:
11             Example :
12             Returns :
13             Args :
14              
15              
16             =cut
17              
18             sub new {
19 22     22 1 70 my($class, %args) = @_;
20 22         67 my $self = bless {}, $class;
21 22         65 $self->init(%args);
22 22         102 return $self;
23             }
24              
25             =head2 init
26              
27             Title : init
28             Usage :
29             Function:
30             Example :
31             Returns :
32             Args :
33              
34              
35             =cut
36              
37             sub init {
38 22     22 1 54 my($self, %args) = @_;
39              
40 22         76 $self->SUPER::_init;
41              
42 22         565 foreach my $arg (keys %args) {
43 63         83 my $meth = $arg;
44 63 100       198 if($self->can($meth)){
45 21         49 $self->$meth($args{$arg});
46             } else {
47 42         91 $self->_style($arg => $args{$arg});
48             }
49             }
50              
51             }
52              
53             =head2 depth
54              
55             Title : depth
56             Usage :
57             Function:
58             Example :
59             Returns :
60             Args :
61              
62              
63             =cut
64              
65             sub depth{
66 22     22 1 36 my ($self,@args) = @_;
67              
68 22         45 my $depth = $self->branch_length;
69              
70 22         28 my $maxdepth = 0;
71 22         65 foreach my $daughter ($self->daughters){
72 21         213 my $ddepth = $daughter->depth;
73 21 50       88 $maxdepth = $ddepth > $maxdepth ? $ddepth : $maxdepth;
74             }
75              
76 22         71 return $depth + $maxdepth;
77             }
78              
79             =head2 branch_length
80              
81             Title : branch_length
82             Usage : $obj->branch_length($newval)
83             Function:
84             Example :
85             Returns : value of branch_length (a scalar)
86             Args : on set, new value (a scalar or undef, optional)
87              
88              
89             =cut
90              
91             sub branch_length{
92 107     107 1 353 my $self = shift;
93              
94 107 100       291 return $self->{'branch_length'} = shift if @_;
95 85   50     1981 return $self->{'branch_length'} || 1;
96             }
97              
98             =head2 branch_type
99              
100             Title : branch_type
101             Usage : $obj->branch_type($newval)
102             Function:
103             Example :
104             Returns : value of branch_type (a scalar)
105             Args : on set, new value (a scalar or undef, optional)
106              
107              
108             =cut
109              
110             sub branch_type{
111 0     0 1 0 my $self = shift;
112              
113 0 0       0 return $self->{'branch_type'} = shift if @_;
114 0         0 return $self->{'branch_type'};
115             }
116              
117             =head2 branch_label
118              
119             Title : branch_label
120             Usage : $obj->branch_label($newval)
121             Function:
122             Example :
123             Returns : value of branch_label (a scalar)
124             Args : on set, new value (a scalar or undef, optional)
125              
126              
127             =cut
128              
129             sub branch_label{
130 21     21 1 1546 my $self = shift;
131              
132 21 50       55 return $self->{'branch_label'} = shift if @_;
133 21         87 return $self->{'branch_label'};
134             }
135              
136             =head2 _style
137              
138             Title : _style
139             Usage : $obj->_style($newval)
140             Function:
141             Example :
142             Returns :
143             Args :
144              
145              
146             =cut
147              
148             sub _style{
149 82     82   97 my $self = shift;
150 82         111 my($key,$val) = @_;
151              
152 82 50 66     448 if(defined($key) and not defined($val)){
    100 66        
153 0         0 return $self->{'_style'}{$key};
154             } elsif(defined($key) and defined($val)){
155 42         111 $self->{'_style'}{$key} = $val;
156 42         149 return $val;
157             } else {
158 40 100       101 return $self->{'_style'} ? %{$self->{'_style'}} : ();
  38         273  
159             }
160             }
161              
162             1;