File Coverage

blib/lib/XML/XBEL/base.pm
Criterion Covered Total %
statement 4 6 66.6
branch n/a
condition n/a
subroutine 2 2 100.0
pod n/a
total 6 8 75.0


line stmt bran cond sub pod time code
1 10     10   68 use strict;
  10         20  
  10         501  
2             package XML::XBEL::base;
3              
4             =head1 NAME
5              
6             XML::XBEL::base - shared private methods for XBEL thingies
7              
8             =head1 SYNOPSIS
9              
10             None.
11              
12             =head1 DESCRIPTION
13              
14             Shared private methods for XBEL thingies.
15              
16             =cut
17              
18             # $Id: base.pm,v 1.3 2004/06/23 04:15:12 asc Exp $
19              
20 10     10   9908 use XML::LibXML;
  0            
  0            
21             use Date::Format;
22              
23             sub _now {
24             my $pkg = shift;
25             return time2str("%Y-%m-%dT%H:%M:%S %z",time);
26             }
27              
28             sub _add_node {
29             my $self = shift;
30             my $node = shift;
31              
32             $self->{'__root'}->addChild($node->{'__root'});
33             }
34              
35             sub _element {
36             my $self = shift;
37             my $element = shift;
38             my $value = shift;
39              
40             if (! $value) {
41             my $el = ($self->{'__root'}->getChildrenByTagName($element))[0];
42             return ($el) ? $el->string_value() : undef;
43             }
44              
45             #
46              
47             if (my $el = ($self->{'__root'}->getChildrenByTagName($element))[0]) {
48             $el->removeChild($el->firstChild());
49             $el->appendText($value);
50             }
51              
52             else {
53             my $node = XML::LibXML::Element->new($element);
54             $node->appendText($value);
55             $self->{'__root'}->addChild($node);
56             }
57              
58             return 1;
59             }
60              
61             sub _attribute {
62             my $self = shift;
63             my $attr = shift;
64             my $value = shift;
65              
66             if (! defined($value)) {
67             return $self->{'__root'}->getAttribute($attr);
68             }
69              
70             $self->{'__root'}->setAttribute($attr,$value);
71             return 1;
72             }
73              
74             =head1 VERSION
75              
76             $Revision: 1.3 $
77              
78             =head1 DATE
79              
80             $Date: 2004/06/23 04:15:12 $
81              
82             =head1 AUTHOR
83              
84             Aaron Straup Cope Eascope@cpan.orgE
85              
86             =head1 SEE ALSO
87              
88            
89              
90             =head1 LICENSE
91              
92             Copyright (c) 2004 Aaron Straup Cope. All Rights Reserved.
93              
94             This is free software, you may use it and distribute it under the
95             same terms as Perl itself.
96              
97             =cut
98              
99             return 1;