Subject: | attributes without class |
It was:
Can't call method "new" on an undefined value at /home/ferz/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/XML/Pastor/Type.pm line 451.
for:
my $class = $attribInfo->{$attribName}->class;
print "\nfrom_xml_dom : Attribute = $attribName, Class = $class" if (!$class || $verbose >= 7);
$self->{$attribPfx . $attribName} = $class->new(__value => $attribs->{$attribName});
I've fixed.
I submit the patch.
Subject: | XML_Pastor_Type.patch |
--- XML/Pastor/Type.pm_orig 2015-04-29 17:05:30.852301815 +0200
+++ XML/Pastor/Type.pm 2015-04-29 17:22:46.132325296 +0200
@@ -444,11 +444,21 @@
my $attribPfx = $type->attributePrefix() || '';
foreach my $attribName (@{$type->effectiveAttributes()}) {
+
next unless ( defined($attribs->{$attribName}));
-
- my $class = $attribInfo->{$attribName}->class();
- print "\nfrom_xml_dom : Attribute = $attribName, Class = $class" if ($verbose >= 7);
- $self->{$attribPfx . $attribName} = $class->new(__value => $attribs->{$attribName});
+
+ if (UNIVERSAL::can($attribInfo->{$attribName}, 'class') && $attribInfo->{$attribName}->class()) {
+ my $class = $attribInfo->{$attribName}->class();
+ print "\nfrom_xml_dom : Attribute = $attribName, Class = $class, node: " . $node->toString if (!$class || $verbose >= 7);
+ $self->{$attribPfx . $attribName} = $class->new(__value => $attribs->{$attribName});
+ } else {
+ eval {
+ $self->$attribName($attribs->{$attribName} || $attribInfo->{$attribName}->{fixed});
+ };
+ if ($@) {
+ croak $attribName . " method fails on " . $self->XmlSchemaType->name;
+ }
+ }
}
}
@@ -456,6 +466,7 @@
# Get the child elements from DOM into self
if (UNIVERSAL::can($type, 'effectiveElementInfo')) {
my $children = getChildrenHashDOM($node);
+
my $elemInfo = $type->effectiveElementInfo();
foreach my $elemName (@{$type->effectiveElements()}) {
@@ -464,11 +475,11 @@
my $elem = $elemInfo->{$elemName} or croak("Undefined child element for '$elemName'!");
my $class = $elem->class() or croak("Undefined class for '$elemName'!");
my $childNodes = $children->{$elemName};
-
+
if ($elem->isSingleton()) {
# singleton
$self->{$elemName} = $class->from_xml_dom($childNodes->[0]);
- }else {
+ } else {
# multiplicity
$self->{$elemName} = XML::Pastor::NodeArray->new(map {$class->from_xml_dom($_)} @$childNodes);
}