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.6
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 46     46   43730 use Apache::ASP::CollectionItem;
  46         161  
  46         2428  
5 46     46   279 use strict;
  46         87  
  46         36981  
6              
7             sub Contents {
8 2     2 0 29 my($self, $key) = @_;
9            
10 2 50       8 if(defined $key) {
11 2         22 $self->Item($key);
12             } else {
13 0         0 $self;
14             }
15             }
16              
17             sub Item {
18 60     60 0 88 my($self, $key, $value) = @_;
19 60         76 my @rv;
20 60         252 my $item_config = $main::Server->Config('CollectionItem');
21              
22 60 100       161 if(defined $value) {
    100          
23 8 50 33     29 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         27 return $self->{$key} = $value;
28             }
29             } elsif(defined $key) {
30 32         60 my $value = $self->{$key};
31 32 100       59 if (defined $value) {
32 26 100 100     104 if(wantarray || $item_config) {
33 20 100       69 @rv = (ref($value) =~ /ARRAY/o) ? @{$value} : ($value);
  14         38  
34             } else {
35 6 100       27 @rv = (ref($value) =~ /ARRAY/o) ? ($value->[0]) : ($value);
36             }
37             } else {
38 6         10 $rv[0] = $value;
39             }
40             } else {
41             # returns hash to self by default, so compat with
42             # $Request->Form() & such null collection calls.
43 20         89 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       64 if ($item_config) {
50 23         85 $rv[0] = Apache::ASP::CollectionItem->new(\@rv);
51             }
52              
53 32 100       164 wantarray ? @rv : $rv[0];
54             }
55              
56             sub Count {
57 2     2 0 3 my $self = shift;
58 2         10 scalar(keys %$self);
59             }
60              
61             sub Key {
62 2     2 0 4 my($self, $index) = @_;
63 2         13 my @keys = sort(keys %$self);
64 2         7 $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;