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