File Coverage

blib/lib/Apache/ASP/Collection.pm
Criterion Covered Total %
statement 31 41 75.6
branch 18 24 75.0
condition 4 6 66.7
subroutine 6 8 75.0
pod 0 6 0.0
total 59 85 69.4


line stmt bran cond sub pod time code
1              
2             package Apache::ASP::Collection;
3              
4 14     14   568 use Apache::ASP::CollectionItem;
  14         150  
  14         307  
5 14     14   233 use strict;
  14         132  
  14         177  
6              
7             sub Contents {
8 2     2 0 26     my($self, $key) = @_;
9                 
10 2 50       26     if(defined $key) {
11 2         40 $self->Item($key);
12                 } else {
13 0         0 $self;
14                 }
15             }
16              
17             sub Item {
18 56     56 0 871     my($self, $key, $value) = @_;
19 56         1211     my @rv;
20 56         628     my $item_config = $main::Server->Config('CollectionItem');
21              
22 56 100       740     if(defined $value) {
    100          
23 8 50 33     94 if(ref($self->{$key}) and $self->{$key} =~ /HASH/) {
24             # multi leveled collection go two levels down
25 0         0 $rv[0] = $self->{$key}{$value};
26             } else {
27 8         93 return $self->{$key} = $value;
28             }
29                 } elsif(defined $key) {
30 32         300 my $value = $self->{$key};
31 32 100       291 if (defined $value) {
32 26 100 100     362 if(wantarray || $item_config) {
33 20 100       292 @rv = (ref($value) =~ /ARRAY/o) ? @{$value} : ($value);
  14         222  
34             } else {
35 6 100       70 @rv = (ref($value) =~ /ARRAY/o) ? ($value->[0]) : ($value);
36             }
37             } else {
38 6         55 $rv[0] = $value;
39             }
40                 } else {
41             # returns hash to self by default, so compat with
42             # $Request->Form() & such null collection calls.
43 16         3383 return $self;
44                 }
45              
46             # coming from the collections we need this like
47             # $Request->QueryString('foo')->Item() syntax, but is incompatible
48             # with $Request->QueryString('foo') syntax
49 32 100       315     if ($item_config) {
50 23         281 $rv[0] = Apache::ASP::CollectionItem->new(\@rv);
51                 }
52              
53 32 100       2306     wantarray ? @rv : $rv[0];
54             }
55              
56             sub Count {
57 2     2 0 80     my $self = shift;
58 2         142     scalar(keys %$self);
59             }
60              
61             sub Key {
62 2     2 0 20     my($self, $index) = @_;
63 2         130     my @keys = sort(keys %$self);
64 2         138     $keys[$index-1];
65             }
66              
67             sub SetProperty {
68 0     0 0       my($self, $property, $key, $value) = @_;
69 0 0             if($property =~ /property/io) {
70             # do this to avoid recursion
71 0           die("can't get the property $property for $self");
72                 } else {
73 0           $self->$property($key, $value);
74                 }
75             }
76              
77             sub GetProperty {
78 0     0 0       my($self, $property, $key) = @_;
79 0 0             if($property =~ /property/io) {
80             # do this to avoid recursion
81 0           die("can't get the property $property for $self");
82                 } else {
83 0           $self->$property($key);
84                 }
85             }
86            
87             1;
88