# URI::Bookmark --
# Perl module class encapsulating a generic bookmark file entry
# (a bookmark, bookmark folder, or entry separator)
#
# Copyright (c) 1999 Adam Spiers <adam@spiers.net>. All rights
# reserved. This program is free software; you can redistribute it and/or
# modify it under the same terms as Perl itself.
#
# $Id: Bookmark.pm,v 1.6 2001/10/08 17:00:09 adam Exp $
#

package URI::Bookmark;

use strict;

require 5.004;
#use AutoLoader qw(AUTOLOAD);
use Carp;

use base qw(Tree::DAG_Node);

=head1 NAME

URI::Bookmark - abstract class for nodes in a bookmark collection

=head1 SYNOPSIS

See L<URI::Bookmarks>.

=head1 DESCRIPTION

URI::Bookmark is a subclass of Tree::DAG_Node, so that each entry in
the bookmark collection is a node in a directed acyclic graph.

Do not access this class directly.  The available subclasses are

   ::Folder        --  a folder containing more entries 
   ::Entry         --  a bookmark entry
   ::Rule          --  a rule separating entries

=cut

sub new {
  my $this = shift;
  my $class = ref $this || $this;
  my $self = Tree::DAG_Node->new();
  bless $self, $class;

  $self->_init(@_);

  return $self;
}

sub _init { } # override this

#1;
########################    End of preloaded code    ########################
#__END__

=head1 METHODS

=head2 set_attribs()

  $bookmark->set_attribs({ name => 'Slashdot',
                           href => 'http://slashdot.org' });

This method should be self-explanatory.  The allowed attributes are:
`name', `href', `add_date', `last_modified', `last_visit',
`aliasof', `aliasid', `description'.  Attempts to set any others will
be ignored and generate a warning.

=cut

sub set_attribs {
  my ($self, $p) = @_;

  while (my ($key, $value) = each %$p) {
    if ($key eq 'name') {
      $self->name($value);
    }
    elsif ($self->attrib_allowed($key)) {
      $self->attributes->{$key} = $value;
    }
    else {
      carp "`$key' is not a valid attribute";
    }
  }
}

=head2 dump_attribs()

  $bookmark->dump_attribs();

Dumps all attribute (key, value) pairs for this node, one per line.
This is only really for debugging.

=cut

sub dump_attribs {
  my $self = shift;

  while (my ($key, $value) = each %{$self->{attributes}}) {
    $value ||= '__undef__';
    print "$key: $value\n";
  }
}

=head1 AUTHOR

Adam Spiers <adam@spiers.net>

=head1 SEE ALSO

L<URI::Bookmarks>

=cut

