RDDL/Directory.pm

filter: Statementstmt 96.8% 31 / 32 Branchbran 75.0% 3 / 4 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 100% 9 / 9 Podpod 100% 7 / 7 totaltotal 92.7% 51 / 55 CC 4 SCAR 5.2
CC
4
Cov
92%
get_resource_by_id
3.0
new
2.1
BEGIN
1.0
CRAP 1.7
« RDDL.pm ↑ Summary RDDL/Driver.pm »
1  
2 ###
3 # XML::RDDL::Directory - RDDL Directory Interface
4 # Robin Berjon <robin@knowscape.com>
5 # 17/10/2001 - v.0.01
6 ###
7  
8 package XML::RDDL::Directory;
9 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 2 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶$VERSION = $XML::RDDL::VERSION || '0.01';
Condition50%1/2
$XML::RDDL::VERSION || '0.01'
l!l
02
MC/DC0%0/1
$XML::RDDL::VERSION || '0.01'
$XML::RDDL::VERSION
Truth table50%1/2
A
A= $XML::RDDL::VERSION
Aresult
11
00
13  
14  
15 #-------------------------------------------------------------------#
16 # constructor
17 #-------------------------------------------------------------------#
18 3 ▶sub new {
Subroutine new: called CC=2 SCAR=7.2
Pod documented
19 3 ▶ my $class = ref($_[0]) ? ref(shift) : shift;
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 0 3 3
20 3 return bless [], $class;
21 }
22 #-------------------------------------------------------------------#
23  
24  
25 #,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,#
26 #`,`, Interface `,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,#
27 #```````````````````````````````````````````````````````````````````#
28  
29 #-------------------------------------------------------------------#
30 # add_resource
31 #-------------------------------------------------------------------#
32 5 ▶sub add_resource {
Subroutine add_resource: called CC=1 SCAR=0.0
Pod documented
33 5 my $d = shift;
34 5 my $res = shift;
35 5 push @$d, $res;
36 }
37 #-------------------------------------------------------------------#
38  
39 #-------------------------------------------------------------------#
40 # delete_resource
41 #-------------------------------------------------------------------#
42 1 ▶sub delete_resource {
Subroutine delete_resource: called CC=1 SCAR=0.0
Pod documented
43 1 my $d = shift;
44 1 my $res = shift;
45 1 @$d = grep { "$res" ne "$_" } @$d;
46 }
47 #-------------------------------------------------------------------#
48  
49 #-------------------------------------------------------------------#
50 # get_resources
51 #-------------------------------------------------------------------#
52 4 ▶sub get_resources {
Subroutine get_resources: called CC=1 SCAR=0.0
Pod documented
53 4 my $d = shift;
54 4 return @$d;
55 }
56 #-------------------------------------------------------------------#
57  
58 #-------------------------------------------------------------------#
59 # get_resource_by_id
60 #-------------------------------------------------------------------#
61 1 ▶sub get_resource_by_id {
Subroutine get_resource_by_id: called CC=3 SCAR=11.1
Pod documented
62 1 my $d = shift;
63 1 my $id = shift;
64 1 for my $r (@$d) {
65 2 ▶ return $r if $r->get_id eq $id;
Branch: 1 branch
BranchTrueFalseTotal
if $r->get_id eq $id 1 1 2
66 }
67 0 return;
68 }
69 #-------------------------------------------------------------------#
70  
71 #-------------------------------------------------------------------#
72 # get_resources_by_nature
73 #-------------------------------------------------------------------#
74 1 ▶sub get_resources_by_nature {
Subroutine get_resources_by_nature: called CC=1 SCAR=0.0
Pod documented
75 1 my $d = shift;
76 1 my $nat = shift;
77 1 return grep { $nat eq $_->get_nature } @$d;
78 }
79 #-------------------------------------------------------------------#
80  
81 #-------------------------------------------------------------------#
82 # get_resources_by_purpose
83 #-------------------------------------------------------------------#
84 1 ▶sub get_resources_by_purpose {
Subroutine get_resources_by_purpose: called CC=1 SCAR=0.0
Pod documented
85 1 my $d = shift;
86 1 my $pur = shift;
87 1 return grep { $pur eq $_->get_purpose } @$d;
88 }
89 #-------------------------------------------------------------------#
90  
91  
92  
93 2 1;
94 #,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,#
95 #`,`, Documentation `,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,#
96 #```````````````````````````````````````````````````````````````````#
97  
98 =pod
99  
100 =head1 NAME
101  
102 XML::RDDL::Directory - RDDL Directory Interface
103  
104 =head1 SYNOPSIS
105  
106 use XML::RDDL::Directory;
107 # create a new RDDL directory
108 my $dir = XML::RDDL::Directory->new;
109 # add some resources
110 $dir->add_resource($res1);
111 $dir->add_resource($res2);
112 # delete a resource
113 $dir->delete_resource($res1);
114 # get resources by various searches
115 $res = $dir->get_resource_by_id('foo');
116 $res = $dir->get_resources_by_nature('http://foobar/nat');
117 $res = $dir->get_resources_by_purpose('http://foobar/purp');
118  
119 =head1 DESCRIPTION
120  
121 XML::RDDL::Directory is a container for all the XML::RDDL::Resources
122 found in one RDDL directory. It has a variety of methods to make
123 access to those resources easier.
124  
125 =head1 METHODS
126  
127 =over 4
128  
129 =item XML::RDDL::Directory->new
130  
131 Creates a new Directory
132  
133 =item add_resource($res1);
134  
135 Adds a given Resource to the Directory
136  
137 =item delete_resource($res1);
138  
139 Deletes a given Resource from the Directory
140  
141 =item get_resources
142  
143 Returns a list of all the resources
144  
145 =item get_resource_by_id('foo');
146  
147 Returns the Resource in the Directory that has that id (nothing if
148 there is none)
149  
150 =item get_resources_by_nature('http://foobar/nat');
151  
152 Returns a (possibly empty) list of Resources in that Directory that
153 have the given nature
154  
155 =item get_resources_by_purpose('http://foobar/purp');
156  
157 Returns a (possibly empty) list of Resources in that Directory that
158 have the given purpose
159  
160 =back
161  
162 =head1 TODO
163  
164 - time will tell if more search methods are needed
165  
166 =head1 AUTHOR
167  
168 Robin Berjon, robin@knowscape.com
169  
170 =head1 COPYRIGHT
171  
172 Copyright (c) 2001-2002 Robin Berjon. All rights reserved. This program is
173 free software; you can redistribute it and/or modify it under the same
174 terms as Perl itself.
175  
176 =head1 SEE ALSO
177  
178 http://www.rddl.org/, XML::RDDL
179  
180 =cut
« RDDL.pm ↑ Summary RDDL/Driver.pm »