The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

URI::Bookmarks - Perl module class encapsulating bookmark files

SYNOPSIS

  use URI::Bookmarks;

  # URI::Bookmarks automagically detects that we're dealing with a
  # collection of Netscape bookmarks

  my $bookmarks =
    new URI::Bookmarks(file => "$ENV{HOME}/.netscape/bookmarks.html");

  my $bookmarks = new URI::Bookmarks(handle => $fh);

  my $bookmarks = new URI::Bookmarks(array => \@lines);
  
  # Manipulate $bookmarks using nice tree methods from Tree::DAG_Node,
  # e.g. delete all bookmarks under $folder:
  ($bookmarks->name_to_nodes($folder))[0]->unlink_from_mother();

  # Then output the new file.
  print $bookmarks->export('Netscape array');

DESCRIPTION

URI::Bookmarks provides a class for manipulating hierarchical collections of bookmarks. Each entry in the collection is an object of type URI::Bookmark, which is in turn a subclass of Tree::DAG_Node, and hence all standard tree manipulation methods are available (see the documentation for Tree::DAG_Node).

  • build_name_lookup

      $bookmarks->build_name_lookup();

    This method builds an internal hash which maps node names to arrays of nodes which have the corresponding key as their name.

    It only needs to be called if you want to rebuild the hash after modifying the bookmark collection in some way; if the hash is needed and has not been built, it will be built automatically.

  • tree_root

      my $tree_root_node = $bookmarks->tree_root();
    
      $bookmarks->tree_root($new_root);

    Returns the current root node of the tree of bookmarks. If the optional parameter is provided, the root node is changed to it.

  • name_to_nodes

      my @nodes = $bookmarks->name_to_nodes('Cinemas');

    Returns an array of all nodes matching the given name.

  • title

      my $title = $bookmarks->title();
    
      $bookmarks->title($new_title);

    Returns the current title of the collection of bookmarks. If the optional parameter is provided, the title is changed to it.

  • origin

      my $origin = $bookmarks->origin();
      my $origin_type = $origin{type};

    Returns a hash containing information about the origin of the collection of bookmarks.

  • export

      my @lines = $bookmarks->export('Netscape array');

    The interface to the export routines. The examples above show the currently available export types.

  • all_URLs

      $bookmarks->all_URLs();

    This method simply returns an array of all the URLs in the collection of bookmarks.

BUGS

The file key of new() might not be safe.

AUTHOR

Adam Spiers <adam@spiers.net>

SEE ALSO

URI::Bookmarks::*, URI::Bookmark, URI::Bookmark::*, perl(1).