File: Library.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 (68 lines) | stat: -rw-r--r-- 1,496 bytes parent folder | download | duplicates (2)
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
59
60
61
62
63
64
65
66
67
68
package XML::Validator::Schema::Library;
use strict;
use warnings;

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

=head1 NAME

XML::Validator::Schema::TypeLibrary - internal base class

=head1 DESCRIPTION

Internal base class used to implement a libraries of named items.

=cut

sub new {
    my $pkg = shift;
    my $self = bless({@_}, $pkg);

    croak("Missing required 'what' parameter.")
      unless $self->{what};
    
    # initialize stacks
    $self->{stacks} = {};

    return $self;
}

sub find_all {
    my $self = shift;
    my @ret;
    foreach my $ns (keys %{$self->{stacks}}) {
        foreach my $name (keys %{$self->{$ns}}) {
            push @ret, $self->{stacks}{$ns}{$name};
        }
    }
    return @ret;
}

sub find {
    my ($self, %arg) = @_;
    croak("Missing required name parameter.") unless $arg{name};

    # HACK: fix when QName resolution works
    $arg{name} =~ s!^[^:]*:!!;
    $arg{ns} ||= XSD;

    return $self->{stacks}{$arg{ns}}{$arg{name}};
}

sub add {
    my ($self, %arg) = @_;
    croak("Missing required name parameter.") unless $arg{name};
    croak("Missing required obj parameter.") unless $arg{obj};
    
    # HACK: fix when QName resolution works
    $arg{name} =~ s!^\w+:!!;
    $arg{ns} ||= XSD;

    _err("Illegal attempt to redefine $self->{what} '$arg{name}' ".
         "in namespace '$arg{ns}'")
      if exists $self->{stacks}{$arg{ns}}{$arg{name}};
    $self->{stacks}{$arg{ns}}{$arg{name}} = $arg{obj};
}

1;