File: ElementRefNode.pm

package info (click to toggle)
libxml-validator-schema-perl 1.10-2.1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 708 kB
  • sloc: perl: 3,682; xml: 16; makefile: 2
file content (58 lines) | stat: -rw-r--r-- 1,414 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package XML::Validator::Schema::ElementRefNode;
use strict;
use warnings;

use base 'XML::Validator::Schema::ElementNode';

use XML::Validator::Schema::Util qw(_err _attr);
use Carp qw(croak);

=head1 NAME

XML::Validator::Schema::ElementRefNode - an element reference node

=head1 DESCRIPTION

This is an internal module used by XML::Validator::Schema to represent
an element reference node.

=cut

sub parse {
    my ($pkg, $data) = @_;
    my $self = $pkg->new();

    my $ref = _attr($data, 'ref');
    croak("Why did you create an ElementRefNode if you didn't have a ref?")
      unless $ref;
    $self->{unresolved_ref} = 1;
    $self->name($ref);

    my $name = _attr($data, 'name');
    _err("Found <element> with illegal combination of 'ref' and 'name' ".
         "attributes.")
      if $name;

    my $type_name = _attr($data, 'type');
    _err("Found <element> with illegal combination of 'ref' and 'type' ".
         "attributes.")
      if $type_name;


    my $min = _attr($data, 'minOccurs');
    $min = 1 unless defined $min;
    _err("Invalid value for minOccurs '$min' found in <element>.")
      unless $min =~ /^\d+$/;
    $self->{min} = $min;

    my $max = _attr($data, 'maxOccurs');
    $max = 1 unless defined $max;
    _err("Invalid value for maxOccurs '$max' found in <element>.")
      unless $max =~ /^\d+$/ or $max eq 'unbounded';
    $self->{max} = $max;

    return $self;
}

1;