File Coverage

blib/lib/Rose/HTML/Object/WithWrapAroundChildren.pm
Criterion Covered Total %
statement 26 26 100.0
branch 11 16 68.7
condition n/a
subroutine 8 8 100.0
pod 0 5 0.0
total 45 55 81.8


line stmt bran cond sub pod time code
1             package Rose::HTML::Object::WithWrapAroundChildren;
2              
3 13     13   122 use strict;
  13         28  
  13         427  
4              
5 13     13   66 use Carp;
  13         31  
  13         2067  
6              
7             our $VERSION = '0.554';
8              
9             use Rose::HTML::Object::MakeMethods::Generic
10             (
11 13         312 array =>
12             [
13             'pre_children' => {},
14             'shift_pre_children' => { interface => 'shift', hash_key => 'pre_children' },
15             'unshift_pre_children' => { interface => 'unshift', hash_key => 'pre_children' },
16             'pop_pre_children' => { interface => 'pop', hash_key => 'pre_children' },
17             'push_pre_children' => { interface => 'push', hash_key => 'pre_children' },
18             'delete_pre_children' => { interface => 'clear', hash_key => 'pre_children' },
19              
20             'post_children' => {},
21             'shift_post_children' => { interface => 'shift', hash_key => 'post_children' },
22             'unshift_post_children' => { interface => 'unshift', hash_key => 'post_children' },
23             'push_post_children' => { interface => 'push', hash_key => 'post_children' },
24             'pop_post_children' => { interface => 'pop', hash_key => 'post_children' },
25             'delete_post_children' => { interface => 'clear', hash_key => 'post_children' },
26             ],
27 13     13   104 );
  13         39  
28              
29             sub children
30             {
31 1197     1197 0 2162 my($self) = shift;
32 1197 50       2557 Carp::croak "Cannot directly set children() for a ", ref($self),
33             ". Use fields(), push_children(), pop_children(), etc." if(@_);
34 1197 100       3518 return wantarray ? ($self->pre_children, $self->immutable_children(), $self->post_children) :
35             [ $self->pre_children, $self->immutable_children(), $self->post_children ];
36             }
37              
38 4     4 0 47 sub push_children { shift->push_post_children(@_) }
39              
40             sub pop_children
41             {
42 4     4 0 13 my($self) = shift;
43              
44 4 50       14 my $num = @_ ? shift : 1;
45 4         19 my @children = $self->pop_post_children($num);
46              
47 4 100       17 if(@children < $num)
48             {
49 1         11 push(@children, $self->pop_pre_children($num - @children));
50             }
51              
52 4 50       25 return @children == 1 ? $children[0] : @children;
53             }
54              
55             sub shift_children
56             {
57 2     2 0 6 my($self) = shift;
58              
59 2 50       6 my $num = @_ ? shift : 1;
60 2         11 my @children = $self->shift_pre_children($num);
61              
62 2 100       8 if(@children < $num)
63             {
64 1         12 push(@children, $self->shift_post_children($num - @children));
65             }
66              
67 2 50       13 return @children == 1 ? $children[0] : @children;
68             }
69              
70 3     3 0 14 sub unshift_children { shift->unshift_pre_children(@_) }
71              
72             1;