XML::RDDL::Directory - RDDL Directory Interface


XML-RDDL documentation Contained in the XML-RDDL distribution.

Index


Code Index:

NAME

Top

XML::RDDL::Directory - RDDL Directory Interface

SYNOPSIS

Top

  use XML::RDDL::Directory;
  # create a new RDDL directory
  my $dir = XML::RDDL::Directory->new;
  # add some resources
  $dir->add_resource($res1);
  $dir->add_resource($res2);
  # delete a resource
  $dir->delete_resource($res1);
  # get resources by various searches
  $res = $dir->get_resource_by_id('foo');
  $res = $dir->get_resources_by_nature('http://foobar/nat');
  $res = $dir->get_resources_by_purpose('http://foobar/purp');

DESCRIPTION

Top

XML::RDDL::Directory is a container for all the XML::RDDL::Resources found in one RDDL directory. It has a variety of methods to make access to those resources easier.

METHODS

Top

XML::RDDL::Directory->new

Creates a new Directory

add_resource($res1);

Adds a given Resource to the Directory

delete_resource($res1);

Deletes a given Resource from the Directory

get_resources

Returns a list of all the resources

get_resource_by_id('foo');

Returns the Resource in the Directory that has that id (nothing if there is none)

get_resources_by_nature('http://foobar/nat');

Returns a (possibly empty) list of Resources in that Directory that have the given nature

get_resources_by_purpose('http://foobar/purp');

Returns a (possibly empty) list of Resources in that Directory that have the given purpose

TODO

Top

  - time will tell if more search methods are needed

AUTHOR

Top

Robin Berjon, robin@knowscape.com

COPYRIGHT

Top

SEE ALSO

Top

http://www.rddl.org/, XML::RDDL


XML-RDDL documentation Contained in the XML-RDDL distribution.

###
# XML::RDDL::Directory - RDDL Directory Interface
# Robin Berjon <robin@knowscape.com>
# 17/10/2001 - v.0.01
###

package XML::RDDL::Directory;
use strict;

use vars qw($VERSION);
$VERSION = $XML::RDDL::VERSION || '0.01';


#-------------------------------------------------------------------#
# constructor
#-------------------------------------------------------------------#
sub new {
    my $class   = ref($_[0]) ? ref(shift) : shift;
    return bless [], $class;
}
#-------------------------------------------------------------------#


#,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,#
#`,`, Interface `,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,#
#```````````````````````````````````````````````````````````````````#

#-------------------------------------------------------------------#
# add_resource
#-------------------------------------------------------------------#
sub add_resource {
    my $d   = shift;
    my $res = shift;
    push @$d, $res;
}
#-------------------------------------------------------------------#

#-------------------------------------------------------------------#
# delete_resource
#-------------------------------------------------------------------#
sub delete_resource {
    my $d   = shift;
    my $res = shift;
    @$d = grep { "$res" ne "$_" } @$d;
}
#-------------------------------------------------------------------#

#-------------------------------------------------------------------#
# get_resources
#-------------------------------------------------------------------#
sub get_resources {
    my $d   = shift;
    return @$d;
}
#-------------------------------------------------------------------#

#-------------------------------------------------------------------#
# get_resource_by_id
#-------------------------------------------------------------------#
sub get_resource_by_id {
    my $d   = shift;
    my $id  = shift;
    for my $r (@$d) {
        return $r if $r->get_id eq $id;
    }
    return;
}
#-------------------------------------------------------------------#

#-------------------------------------------------------------------#
# get_resources_by_nature
#-------------------------------------------------------------------#
sub get_resources_by_nature {
    my $d   = shift;
    my $nat = shift;
    return grep { $nat eq $_->get_nature } @$d;
}
#-------------------------------------------------------------------#

#-------------------------------------------------------------------#
# get_resources_by_purpose
#-------------------------------------------------------------------#
sub get_resources_by_purpose {
    my $d   = shift;
    my $pur = shift;
    return grep { $pur eq $_->get_purpose } @$d;
}
#-------------------------------------------------------------------#



1;
#,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,#
#`,`, Documentation `,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,#
#```````````````````````````````````````````````````````````````````#