SVG
view release on metacpan or search on metacpan
lib/SVG/DOM.pm view on Meta::CPAN
if ( exists $idlist->{$id} ) {
return $idlist->{$id};
}
return;
}
*getElementbyID = \&getElementByID;
#-----------------
# sub getAttribute
# see also SVG::attrib()
sub getAttribute {
my ( $self, $attr ) = @_;
if ( exists $self->{$attr} ) {
return $self->{$attr};
}
return;
}
#-----------------
# sub getAttributes
sub getAttributes {
my $self = shift;
my $out = {};
foreach my $i ( keys %$self ) {
$out->{$i} = $self->{$i} unless $i =~ /^-/;
}
return wantarray ? %{$out} : $out;
}
#-----------------
# sub setAttribute
sub setAttributes {
my ( $self, $attr ) = @_;
foreach my $i ( keys %$attr ) {
$self->attrib( $i, $attr->{$i} );
}
}
#-----------------
# sub setAttribute
sub setAttribute {
my ( $self, $att, $val ) = @_;
$self->attrib( $att, $val );
}
#-----------------
# sub getCDATA / getCdata / getData
sub getCDATA {
my $self = shift;
if ( exists $self->{-cdata} ) {
return $self->{-cdata};
}
return;
}
*getCdata = \&getCDATA;
*getData = \&getCDATA;
# ----------------
# 2005-12-30 - Martin Owens, apply greater DOM specification (write)
# http://www.w3.org/TR/1998/REC-DOM-Level-1-19981001/level-one-core.html
# ----------------
# sub document
sub document {
my ($self) = @_;
return $self->{-docref};
}
# DOM specified method names
*createElement = \&tag;
*firstChild = \&getFirstChild;
*lastChild = \&getLastChild;
*previousSibling = \&getPreviousSibling;
*nextSibling = \&getNextSibling;
# ----------------
# sub insertBefore
sub insertBefore {
my ( $self, $newChild, $refChild ) = @_;
return $self->appendElement($newChild) if not $refChild;
my $index = $self->findChildIndex($refChild);
return 0 if $index < 0; # NO_FOUND_ERR
return $self->insertAtIndex( $newChild, $index );
}
*insertChildBefore = \&insertBefore;
*insertNodeBefore = \&insertBefore;
*insertElementBefore = \&insertBefore;
# ----------------
# sub insertAfter
sub insertAfter {
my ( $self, $newChild, $refChild ) = @_;
return $self->appendElement($newChild) if not $refChild;
my $index = $self->findChildIndex($refChild);
return 0 if $index < 0; # NO_FOUND_ERR
return $self->insertAtIndex( $newChild, $index + 1 );
}
*insertChildAfter = \&insertAfter;
*insertNodeAfter = \&insertAfter;
*insertElementAfter = \&insertAfter;
# ----------------
# sub insertSiblingAfter (Not in W3C DOM)
sub insertSiblingAfter {
my ( $self, $newChild ) = @_;
return $self->getParent->insertAfter( $newChild, $self )
if $self->getParent;
return 0;
}
lib/SVG/DOM.pm view on Meta::CPAN
Return the next child element of the parent node, or undef if this is the last child.
=head2 $ref = $obj->getPreviousSibling()
Return the previous child element of the parent node, or undef if this is the first child.
=head2 $index = $obj->getChildIndex()
Return the place of this element in the parent node's list of children, starting from 0.
=head2 $element = $obj->getChildAtIndex($index)
Returns the child element at the specified index in the parent node's list of children.
=head2 $ref = $obj->getParentElement()
Return the parent of the current node.
Alias: getParent()
=head2 @refs = $obj->getParentElements()
Return a list of the parents of the current node, starting from the immediate parent. The
last member of the list should be the document element.
Alias: getParents()
=head2 $name = $obj->getElementName()
Return a string containing the name (i.e. the type, not the ID) of an element.
Alias: getType(), getTagName(), getNodeName()
=head2 $ref = $svg->getElementByID($id)
Alias: getElementbyID()
Return a reference to the element which has ID $id, or undef if no element with this ID exists.
=head2 $id = $obj->getElementID()
Return a string containing the ID of the current node, or undef if it has no ID.
=head2 $ref = $obj->getAttributes()
Return a hash reference of attribute names and values for the current node.
=head2 $value = $obj->getAttribute($name);
Return the string value attribute value for an attribute of name $name.
=head2 $ref = $obj->setAttributes({name1=>$value1,name2=>undef,name3=>$value3})
Set a set of attributes. If $value is undef, deletes the attribute.
=head2 $value = $obj->setAttribute($name,$value);
Set attribute $name to $value. If $value is undef, deletes the attribute.
=head2 $cdata = $obj->getCDATA()
Return the canonical data (i.e. textual content) of the current node.
Alias: getCdata(), getData()
=head2 $boolean = $obj->isAncestor($element)
Returns 1 if the current node is an ancestor of the specified element, otherwise 0.
=head2 $boolean = $obj->isDescendant($element)
Returns 1 if the current node is a descendant of the specified element, otherwise 0.
=head2 $boolean = $obj->insertBefore( $element, $child );
Returns 1 if $element was successfully inserted before $child in $obj
=head2 $boolean = $obj->insertAfter( $element, $child );
Returns 1 if $element was successfully inserted after $child in $obj
=head2 $boolean = $obj->insertSiblingBefore( $element );
Returns 1 if $element was successfully inserted before $obj
=head2 $boolean = $obj->insertSiblingAfter( $element );
Returns 1 if $element was successfully inserted after $obj
=head2 $element = $obj->replaceChild( $element, $child );
Returns $child if $element successfully replaced $child in $obj
=head2 $element = $obj->removeChild( $child );
Returns $child if it was removed successfully from $obj
=head2 $element = $obj->cloneNode( $deep );
Returns a new $element clone of $obj, without parents or children. If deep is set to 1, all children are included recursively.
=head1 AUTHOR
Ronan Oger, ronan@roitsystems.com
Martin Owens, doctormo@postmaster.co.uk
=head1 SEE ALSO
perl(1), L<SVG>, L<SVG::XML>, L<SVG::Element>, L<SVG::Parser>
L<http://www.w3c.org/Graphics/SVG/> SVG at the W3C
=cut
1;
( run in 1.112 second using v1.01-cache-2.11-cpan-75ffa21a3d4 )