Subject: | SVG::DOM insertSiblingAfter calls nonexistent 'parent' method |
Date: | Fri, 24 Apr 2015 14:42:03 +0300 |
To: | bug-svg [...] rt.cpan.org |
From: | Marius Gavrilescu <marius [...] ieval.ro> |
This program:
#!/usr/bin/perl
use v5.14;
use warnings;
use SVG;
my $svg = SVG->new;
my $circle = $svg->circle(cx => 20, cy => 20, r => 18);
$circle->insertSiblingAfter($circle);
say $svg->xmlify;
Dies with:
Show quoted text
> Can't locate object method "parent" via package "SVG::Element" at
> /usr/local/share/perl/5.20.2/SVG/DOM.pm line 435.
Relevant part of SVG::DOM:
Show quoted text> sub insertSiblingAfter {
> my ( $self, $newChild ) = @_;
> return $self->parent->insertAfter( $newChild, $self ) if $self->parent;
> return 0;
> }
'parent' should be 'getParent'. This patch fixes the problem and adds a
test:
From 499d04560d67ad7c93654557b6e30f8163a077d0 Mon Sep 17 00:00:00 2001
From: Marius Gavrilescu <marius@ieval.ro>
Date: Fri, 24 Apr 2015 14:40:51 +0300
Subject: [PATCH] Fix insertSibling{After,Before} methods
---
lib/SVG/DOM.pm | 4 ++--
t/16-siblings.t | 4 +++-
2 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/lib/SVG/DOM.pm b/lib/SVG/DOM.pm
index 9a59c55..d87984e 100644
--- a/lib/SVG/DOM.pm
+++ b/lib/SVG/DOM.pm
@@ -432,7 +432,7 @@ sub insertAfter {
# sub insertSiblingAfter (Not in W3C DOM)
sub insertSiblingAfter {
my ( $self, $newChild ) = @_;
- return $self->parent->insertAfter( $newChild, $self ) if $self->parent;
+ return $self->getParent->insertAfter( $newChild, $self ) if $self->getParent;
return 0;
}
@@ -440,7 +440,7 @@ sub insertSiblingAfter {
# sub insertSiblingBefore (Not in W3C DOM)
sub insertSiblingBefore {
my ( $self, $newChild ) = @_;
- return $self->parent->insertBefore( $newChild, $self ) if $self->parent;
+ return $self->getParent->insertBefore( $newChild, $self ) if $self->getParent;
return 0;
}
diff --git a/t/16-siblings.t b/t/16-siblings.t
index 9e7b748..1cc31cc 100755
--- a/t/16-siblings.t
+++ b/t/16-siblings.t
@@ -1,7 +1,7 @@
use strict;
use warnings;
-use Test::More tests => 3;
+use Test::More tests => 4;
use SVG;
# test: getFirstChild, getLastChild, getParent, getChildren
@@ -15,3 +15,5 @@ ok( $child1->hasSiblings(), "hasSiblings" );
is( $child1->getNextSibling(), $child2, "getNextSibling" );
is( $child2->getPreviousSibling(), $child1, "getPreviousSibling" );
+$child2->insertSiblingAfter($child1);
+is( $child2->getNextSibling(), $child1, "insertSiblingAfter" );
--
2.1.4
--
Marius Gavrilescu
Message body not shown because it is not plain text.