XML::XBEL::base - shared private methods for XBEL thingies


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

Index


Code Index:

NAME

Top

XML::XBEL::base - shared private methods for XBEL thingies

SYNOPSIS

Top

 None.

DESCRIPTION

Top

Shared private methods for XBEL thingies.

VERSION

Top

$Revision: 1.3 $

DATE

Top

$Date: 2004/06/23 04:15:12 $

AUTHOR

Top

Aaron Straup Cope <ascope@cpan.org>

SEE ALSO

Top

<XML::XBEL>

LICENSE

Top

Copyright (c) 2004 Aaron Straup Cope. All Rights Reserved.

This is free software, you may use it and distribute it under the same terms as Perl itself.


XML-XBEL documentation Contained in the XML-XBEL distribution.
use strict;
package XML::XBEL::base;

# $Id: base.pm,v 1.3 2004/06/23 04:15:12 asc Exp $

use XML::LibXML;
use Date::Format;

sub _now {
    my $pkg = shift;
    return time2str("%Y-%m-%dT%H:%M:%S %z",time);
}

sub _add_node {
    my $self = shift;
    my $node = shift;

    $self->{'__root'}->addChild($node->{'__root'});
}

sub _element {
    my $self    = shift;
    my $element = shift;
    my $value   = shift;

    if (! $value) {
	my $el = ($self->{'__root'}->getChildrenByTagName($element))[0];
	return ($el) ? $el->string_value() : undef;
    }

    #

    if (my $el = ($self->{'__root'}->getChildrenByTagName($element))[0]) {
	$el->removeChild($el->firstChild());
	$el->appendText($value);
    }

    else {
	my $node = XML::LibXML::Element->new($element);
	$node->appendText($value);
	$self->{'__root'}->addChild($node);
    }

    return 1;
}

sub _attribute {
    my $self  = shift;
    my $attr  = shift;
    my $value = shift;

    if (! defined($value)) {
	return $self->{'__root'}->getAttribute($attr);
    }

    $self->{'__root'}->setAttribute($attr,$value);
    return 1;
}

return 1;