File Coverage

blib/lib/Rose/HTML/Object/Repeatable.pm
Criterion Covered Total %
statement 45 49 91.8
branch 19 22 86.3
condition 4 5 80.0
subroutine 11 12 91.6
pod 2 6 33.3
total 81 94 86.1


line stmt bran cond sub pod time code
1             package Rose::HTML::Object::Repeatable;
2              
3 2     2   16 use strict;
  2         4  
  2         59  
4              
5 2     2   9 use Carp;
  2         5  
  2         113  
6 2     2   12 use Clone::PP();
  2         4  
  2         32  
7              
8 2     2   8 use base 'Rose::HTML::Form';
  2         4  
  2         307  
9              
10             our $VERSION = '0.613';
11              
12             #
13             # Class data
14             #
15              
16             use Rose::Class::MakeMethods::Generic
17             (
18 2         33 inheritable_scalar =>
19             [
20             'default_prototype_class',
21             ],
22 2     2   15 );
  2         22  
23              
24             #
25             # Object data
26             #
27              
28             use Rose::Object::MakeMethods::Generic
29             (
30 2         21 scalar =>
31             [
32             'default_count' => { interface => 'get_set_init' },
33             'prototype',
34             ],
35 2     2   380 );
  2         5  
36              
37 0     0 0 0 sub init_default_count { 0 }
38              
39 7     7 1 29 sub is_repeatable { 1 }
40              
41             sub prototype_class
42             {
43 10     10 0 18 my($self) = shift;
44              
45 10 100       25 if(@_)
46             {
47 4         13 return $self->{'prototype_class'} = shift;
48             }
49              
50 6   66     53 return $self->{'prototype_class'} || ref($self)->default_prototype_class;
51             }
52              
53             sub prototype_spec
54             {
55 9     9 0 24 my($self) = shift;
56              
57 9 100       25 if(@_)
58             {
59 3 50       9 if(@_ == 1)
60             {
61 3 50       14 if(ref($_[0]) eq 'ARRAY')
    50          
62             {
63 0         0 $self->{'prototype_spec'} = shift;
64             }
65             elsif(ref($_[0]) eq 'HASH')
66             {
67 3         7 $self->{'prototype_spec'} = shift;
68             }
69             else
70             {
71 0         0 croak "Invalid prototype spec: @_";
72             }
73             }
74             else
75             {
76 0         0 $self->{'prototype_spec'} = [ @_ ];
77             }
78             }
79              
80 9         42 return $self->{'prototype_spec'};
81             }
82              
83             sub prototype_clone
84             {
85 34     34 0 61 my($self) = shift;
86              
87 34 100       104 if(my $obj = $self->prototype)
88             {
89 28         91 return Clone::PP::clone($obj);
90             }
91             else
92             {
93 6   100     21 my $args = $self->prototype_spec || [];
94 6 100       34 $args = [ %$args ] if(ref $args eq 'HASH');
95 6         25 return $self->prototype_class->new(@$args);
96             }
97             }
98              
99             sub empty_is_ok
100             {
101 41     41 1 79 my($self) = shift;
102              
103 41 100       90 if(@_)
104             {
105 4         12 foreach my $form ($self->forms)
106             {
107 2         15 $form->empty_is_ok(@_);
108             }
109              
110 4 100       32 return $self->{'empty_is_ok'} = $_[0] ? 1 : 0;
111             }
112              
113 37         82 my $forms = $self->forms;
114              
115 37 100       113 return $self->{'empty_is_ok'} unless(@$forms);
116              
117 27         66 foreach my $form (@$forms)
118             {
119 28 100       76 return 0 unless($form->empty_is_ok);
120             }
121              
122 6         23 return 1;
123             }
124              
125             1;