File Coverage

blib/lib/Lim/RPC/Value/Collection.pm
Criterion Covered Total %
statement 9 40 22.5
branch 0 22 0.0
condition 0 15 0.0
subroutine 3 10 30.0
pod 6 6 100.0
total 18 93 19.3


line stmt bran cond sub pod time code
1             package Lim::RPC::Value::Collection;
2              
3 7     7   45 use common::sense;
  7         17  
  7         60  
4 7     7   326 use Carp;
  7         96  
  7         562  
5              
6 7     7   43 use Lim ();
  7         16  
  7         8003  
7              
8             =encoding utf8
9              
10             =head1 NAME
11              
12             ...
13              
14             =head1 VERSION
15              
16             See L for version.
17              
18             =over 4
19              
20             =item OPT_REQUIRED
21              
22             =item OPT_SWALLOW
23              
24             =back
25              
26             =cut
27              
28             our $VERSION = $Lim::VERSION;
29              
30             sub OPT_REQUIRED (){ 0x00000001 }
31             sub OPT_SWALLOW (){ 0x00000002 }
32              
33             our %OPTIONS = (
34             'required' => OPT_REQUIRED,
35             'swallow' => OPT_SWALLOW
36             );
37              
38             =head1 SYNOPSIS
39              
40             ...
41              
42             =head1 SUBROUTINES/METHODS
43              
44             =head2 new
45              
46             =cut
47              
48             sub new {
49 0     0 1   my $this = shift;
50 0   0       my $class = ref($this) || $this;
51 0 0         my %args = scalar @_ > 1 ? ( @_ ) : ( textual => $_[0] );
52 0           my $self = {
53             options => 0
54             };
55            
56 0 0         if (exists $args{textual}) {
57 0           foreach (split(/\s+/o, lc($args{textual}))) {
58 0 0         if (exists $OPTIONS{$_}) {
59 0           $self->{options} |= $OPTIONS{$_};
60             }
61             else {
62 0           confess __PACKAGE__, ': unknown RPC value collection setting "'.$_.'"';
63             }
64             }
65             }
66             else {
67 0 0 0       unless (defined $args{children} and ref($args{children}) eq 'HASH') {
68 0           confess __PACKAGE__, ': No children specified or invalid';
69             }
70 0           $self->{children} = $args{children};
71            
72 0 0         if (defined $args{options}) {
73 0 0         unless (ref($args{options}) eq 'ARRAY') {
74 0           confess __PACKAGE__, ': Invalid options specified';
75             }
76            
77 0           foreach (@{$args{options}}) {
  0            
78 0 0         if (exists $OPTIONS{$_}) {
79 0           $self->{options} |= $OPTIONS{$_};
80             }
81             else {
82 0           confess __PACKAGE__, ': Unknown RPC value collection option "'.$_.'"';
83             }
84             }
85             }
86             }
87            
88 0           bless $self, $class;
89             }
90              
91             sub DESTROY {
92 0     0     my ($self) = @_;
93             }
94              
95             =head2 children
96              
97             =cut
98              
99             sub children {
100 0     0 1   $_[0]->{children};
101             }
102              
103             =head2 set_children
104              
105             =cut
106              
107             sub set_children {
108 0 0 0 0 1   if (defined $_[1] and ref($_[1]) eq 'HASH') {
109 0           $_[0]->{children} = $_[1];
110             }
111            
112 0           $_[0];
113             }
114              
115             =head2 required
116              
117             =cut
118              
119             sub required {
120 0 0   0 1   $_[0]->{options} & OPT_REQUIRED ? 1 : 0;
121             }
122              
123             =head2 swallow
124              
125             =cut
126              
127             sub swallow {
128 0 0   0 1   $_[0]->{options} & OPT_SWALLOW ? 1 : 0;
129             }
130              
131             =head2 comform
132              
133             =cut
134              
135             sub comform {
136 0 0 0 0 1   unless (defined $_[1] and (ref($_[1]) eq 'HASH' or ref($_[1]) eq 'ARRAY')) {
      0        
137 0           return 0;
138             }
139 0           return 1;
140             }
141              
142             =head1 AUTHOR
143              
144             Jerry Lundström, C<< >>
145              
146             =head1 BUGS
147              
148             Please report any bugs or feature requests to L.
149              
150             =head1 SUPPORT
151              
152             You can find documentation for this module with the perldoc command.
153              
154             perldoc Lim
155              
156             You can also look for information at:
157              
158             =over 4
159              
160             =item * Lim issue tracker (report bugs here)
161              
162             L
163              
164             =back
165              
166             =head1 ACKNOWLEDGEMENTS
167              
168             =head1 LICENSE AND COPYRIGHT
169              
170             Copyright 2012-2013 Jerry Lundström.
171              
172             This program is free software; you can redistribute it and/or modify it
173             under the terms of either: the GNU General Public License as published
174             by the Free Software Foundation; or the Artistic License.
175              
176             See http://dev.perl.org/licenses/ for more information.
177              
178              
179             =cut
180              
181             1; # End of Lim::RPC::Value::Collection