File Coverage

blib/lib/Router/Boom/Node.pm
Criterion Covered Total %
statement 28 29 96.5
branch 3 4 75.0
condition n/a
subroutine 8 8 100.0
pod 0 2 0.0
total 39 43 90.7


line stmt bran cond sub pod time code
1             package Router::Boom::Node;
2 6     6   19 use strict;
  6         5  
  6         123  
3 6     6   16 use warnings;
  6         3  
  6         99  
4 6     6   1348 use utf8;
  6         24  
  6         17  
5 6     6   154 use 5.008_001;
  6         11  
6              
7             use Class::Accessor::Lite 0.05 (
8 6         35 rw => [qw(leaf)],
9             ro => [qw(key children)],
10 6     6   2244 );
  6         4694  
11              
12             sub new {
13 33     33 0 27 my $class = shift;
14 33 50       73 my %args = @_==1 ? %{$_[0]} : @_;
  0         0  
15 33         117 bless {
16             children => +[],
17             %args,
18             }, $class;
19             }
20              
21 6     6   661 use re 'eval';
  6         6  
  6         633  
22              
23             sub add_node {
24 32     32 0 26 my ($self, $child) = @_;
25 32         28 for (my $i=0; $i<@{$self->{children}}; $i++) {
  47         81  
26 20 100       34 if ($self->{children}->[$i]->{key} eq $child) {
27 5         22 return $self->{children}->[$i];
28             }
29             }
30 27         18 push @{$self->{children}}, Router::Boom::Node->new(key => $child);
  27         40  
31 27         100 return $self->{children}->[-1];
32             }
33              
34             =pod
35              
36             sub as_arrayref {
37             my ($self) = @_;
38             [$self->key, [map { $_->as_arrayref } @{$self->children}], $self->leaf];
39             }
40              
41             =cut
42              
43             1;
44