line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
### |
3
|
|
|
|
|
|
|
# XML::RDDL::Directory - RDDL Directory Interface |
4
|
|
|
|
|
|
|
# Robin Berjon |
5
|
|
|
|
|
|
|
# 17/10/2001 - v.0.01 |
6
|
|
|
|
|
|
|
### |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
package XML::RDDL::Directory; |
9
|
2
|
|
|
2
|
|
12
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
71
|
|
10
|
|
|
|
|
|
|
|
11
|
2
|
|
|
2
|
|
18
|
use vars qw($VERSION); |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
878
|
|
12
|
|
|
|
|
|
|
$VERSION = $XML::RDDL::VERSION || '0.01'; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
#-------------------------------------------------------------------# |
16
|
|
|
|
|
|
|
# constructor |
17
|
|
|
|
|
|
|
#-------------------------------------------------------------------# |
18
|
|
|
|
|
|
|
sub new { |
19
|
3
|
50
|
|
3
|
1
|
545
|
my $class = ref($_[0]) ? ref(shift) : shift; |
20
|
3
|
|
|
|
|
24
|
return bless [], $class; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
#-------------------------------------------------------------------# |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
#,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,# |
26
|
|
|
|
|
|
|
#`,`, Interface `,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,# |
27
|
|
|
|
|
|
|
#```````````````````````````````````````````````````````````````````# |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
#-------------------------------------------------------------------# |
30
|
|
|
|
|
|
|
# add_resource |
31
|
|
|
|
|
|
|
#-------------------------------------------------------------------# |
32
|
|
|
|
|
|
|
sub add_resource { |
33
|
5
|
|
|
5
|
1
|
229
|
my $d = shift; |
34
|
5
|
|
|
|
|
9
|
my $res = shift; |
35
|
5
|
|
|
|
|
25
|
push @$d, $res; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
#-------------------------------------------------------------------# |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
#-------------------------------------------------------------------# |
40
|
|
|
|
|
|
|
# delete_resource |
41
|
|
|
|
|
|
|
#-------------------------------------------------------------------# |
42
|
|
|
|
|
|
|
sub delete_resource { |
43
|
1
|
|
|
1
|
1
|
2
|
my $d = shift; |
44
|
1
|
|
|
|
|
2
|
my $res = shift; |
45
|
1
|
|
|
|
|
3
|
@$d = grep { "$res" ne "$_" } @$d; |
|
4
|
|
|
|
|
16
|
|
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
#-------------------------------------------------------------------# |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
#-------------------------------------------------------------------# |
50
|
|
|
|
|
|
|
# get_resources |
51
|
|
|
|
|
|
|
#-------------------------------------------------------------------# |
52
|
|
|
|
|
|
|
sub get_resources { |
53
|
4
|
|
|
4
|
1
|
105
|
my $d = shift; |
54
|
4
|
|
|
|
|
16
|
return @$d; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
#-------------------------------------------------------------------# |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
#-------------------------------------------------------------------# |
59
|
|
|
|
|
|
|
# get_resource_by_id |
60
|
|
|
|
|
|
|
#-------------------------------------------------------------------# |
61
|
|
|
|
|
|
|
sub get_resource_by_id { |
62
|
1
|
|
|
1
|
1
|
2
|
my $d = shift; |
63
|
1
|
|
|
|
|
2
|
my $id = shift; |
64
|
1
|
|
|
|
|
4
|
for my $r (@$d) { |
65
|
2
|
100
|
|
|
|
11
|
return $r if $r->get_id eq $id; |
66
|
|
|
|
|
|
|
} |
67
|
0
|
|
|
|
|
0
|
return; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
#-------------------------------------------------------------------# |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
#-------------------------------------------------------------------# |
72
|
|
|
|
|
|
|
# get_resources_by_nature |
73
|
|
|
|
|
|
|
#-------------------------------------------------------------------# |
74
|
|
|
|
|
|
|
sub get_resources_by_nature { |
75
|
1
|
|
|
1
|
1
|
3
|
my $d = shift; |
76
|
1
|
|
|
|
|
2
|
my $nat = shift; |
77
|
1
|
|
|
|
|
4
|
return grep { $nat eq $_->get_nature } @$d; |
|
3
|
|
|
|
|
9
|
|
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
#-------------------------------------------------------------------# |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
#-------------------------------------------------------------------# |
82
|
|
|
|
|
|
|
# get_resources_by_purpose |
83
|
|
|
|
|
|
|
#-------------------------------------------------------------------# |
84
|
|
|
|
|
|
|
sub get_resources_by_purpose { |
85
|
1
|
|
|
1
|
1
|
2
|
my $d = shift; |
86
|
1
|
|
|
|
|
2
|
my $pur = shift; |
87
|
1
|
|
|
|
|
3
|
return grep { $pur eq $_->get_purpose } @$d; |
|
3
|
|
|
|
|
7
|
|
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
#-------------------------------------------------------------------# |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
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 |