File Coverage

blib/lib/XRI/Descriptor.pm
Criterion Covered Total %
statement 34 34 100.0
branch 5 10 50.0
condition 2 6 33.3
subroutine 7 7 100.0
pod 0 5 0.0
total 48 62 77.4


line stmt bran cond sub pod time code
1             # Copyright (C) 2004 Identity Commons. All Rights Reserved.
2             # See LICENSE for licensing details
3              
4             # Authors:
5             # Fen Labalme
6             # Eugene Eric Kim
7              
8             package XRI::Descriptor;
9              
10             our $VERSION = 0.1;
11              
12 4     4   30694 use XRI::Descriptor::LocalAccess;
  4         13  
  4         124  
13 4     4   7981 use XML::Smart;
  4         135493  
  4         1884  
14              
15             sub new {
16 6     6 0 18737 my $self = shift;
17 6         15 my $xml = shift;
18 6         26 my $doc = XML::Smart->new( $xml );
19 6         25857 $doc = $doc->{XRIDescriptor};
20              
21 6         1106 bless { doc=>$doc }, $self;
22             }
23              
24             sub getResolved {
25 1     1 0 73 my $self = shift;
26              
27 1         5 return $self->{doc}{Resolved};
28             }
29              
30             # returns a reference to a list of URIs
31             #
32             sub getXRIAuthorityURIs {
33 3     3 0 167 my $self = shift;
34              
35 3         6 return \@{$self->{doc}{XRIAuthority}{URI}};
  3         9  
36             }
37              
38             sub getLocalAccess {
39 1     1 0 76 my $self = shift;
40 1         2 my ($service, $type) = @_;
41              
42 1         3 my @localAccessObjects;
43 1         2 my @localAccessElements = @{$self->{doc}->{LocalAccess}};
  1         4  
44              
45 1         309 foreach my $element (@localAccessElements) {
46 1         115 my $object = XRI::Descriptor::LocalAccess->new;
47 1 50       4 $object->service($element->{Service}) if ($element->{Service});
48 1 50 33     218 if (!$service || $object->service eq $service) {
49 1 50       106 if ($element->{URI}) {
50             # this conditional should be unnecessary if XML is valid.
51             # according to the schema, there should always be at least
52             # one URI per LocalAccess object.
53 1         198 $object->uris($element->{URI});
54             }
55 1 50       5 $object->types($element->{Type}) if $element->{Type};
56 1 50 33     267 if (!$type || grep(/^$type$/, $object->types)) {
57 1         49 push @localAccessObjects, $object;
58             }
59             }
60             }
61 1         5 return @localAccessObjects;
62             }
63              
64             sub getMappings {
65 1     1 0 61 my $self = shift;
66              
67 1         2 return \@{$self->{doc}{Mapping}};
  1         4  
68             }
69              
70             1;
71             __END__