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

E2::Node - A module for loading nodes from everything2.com based on title or node_id

SYNOPSIS

        use E2::Node;

        my $node = new E2::Node;
        $node->login( "username", "password" ); # See E2::Interface

        if( $node->load( "Butterfinger McFlurry" ) ) {
                print "Title: " . $node->title;
                print "\nAuthor: " . $node->author;
                print "\nCreatetime: " . $node->createtime;
        }

        # List softlinks
        
        print "\nSoftlinks:\n";
        foreach my $s ($node->list_softlinks) {
                print $s->{title} . "\n";
        }

DESCRIPTION

This module is the base class for all e2interface modules that load data from everything2.com based on title or node_id. It allows access to the data in those nodes, and its subclasses provide data exclusive to their particular node types.

This module provides generic methods to load and parse nodes, and is also capable of detecting the type of node passed to it and re-blessing itself into the proper subclass.

This module inherits E2::Interface.

CONSTRUCTOR

new

new creates a new E2::Node object.

METHODS

$node->title
$node->node_id
$node->author
$node->author_id
$node->createtime
$node->type

These methods return, respectively, the title of the node, the node_id, the author, the user_id of the author, the createtime (in the format "YYYY-MM-DD HH:MM:SS"), or the type, of the current node. They return undef if there is no node currently loaded.

$node->exists

This method returns a boolean value in answer to the question "Does this node exist?" This can be used to test whether or not a node has been loaded correctly.

$node->load TITLE [, TYPE ]
$node->load_by_id NODE_ID
$node->load_from_xml XML_STRING

These methods load a node based upon, respectively, TITLE, NODE_ID, or XML_STRING. They populate a number of internal variables, which are accessable through the access methods listed above.

load_from_xml expects to be passed an XML string of the type generated by a query to everything2.com with 'displaytype=xmltrue' set.

load and load_by_id fetch the appropriate page from everything2.com. For load, if TYPE is specified, it fetches the node of that type. If no appropriate node of that type exists, they return undef. Otherwise, they return true.

If the object that's doing the loading is of this class, rather than one of its descendants, the load methods will attempt to determine from the XML the type of node they were passed, and then re-bless the current object into that class. These are the classes an E2::Node object will be re-blessed into based on node type:

        e2node          => E2::E2Node
        writeup         => E2::E2Node   # NOTE: Not E2::Writeup
        user            => E2::User
        usergroup       => E2::Usergroup
        superdoc        => E2::Superdoc

And here's an example:

        my $node = new E2::Node;

        # At ths point, $node is of class 'E2::Node'

        $node->load( "Brian Eno", "e2node" );

        # Now $node is of class 'E2::E2Node' and has access to
        # all the methods of that class.

Note: once an object has been re-blessed, it is a member of the new class, and therefore will generate an exception if it calls one of the load methods on a different type of node.

        # (continued from above)

        $node->load( "nate", "user" ); # throws 'Wrong node type:' exception.

Once the object has been re-blessed, if we wish to autodetect node type again, we must call E2::Node->new on the object.

Exceptions: 'Unable to process request', 'Wrong node type:', 'Parse error:', 'Invalid node type:'

SEE ALSO

E2::Interface, E2::Node, E2::E2Node, E2::Writeup, E2::Superdoc, http://everything2.com, http://everything2.com/?node=clientdev

AUTHOR

Jose M. Weeks <jose@joseweeks.com> (Simpleton on E2)

COPYRIGHT

This software is public domain.