| 1 | package XML::Validator::Schema::Util; | ||||||||||
| 2 | 6 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 6 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | =head1 NAME | ||||||||||
| 6 | |||||||||||
| 7 | XML::Validator::Schema::Util | ||||||||||
| 8 | |||||||||||
| 9 | =head1 DESCRIPTION | ||||||||||
| 10 | |||||||||||
| 11 | This is an internal module containing a few commonly used functions. | ||||||||||
| 12 | |||||||||||
| 13 | =cut | ||||||||||
| 14 | |||||||||||
| 15 | 6 | require Exporter; | |||||||||
| 16 | 6 | our @ISA = qw(Exporter); | |||||||||
| 17 | 6 | our @EXPORT_OK = qw(_attr _err XSD); | |||||||||
| 18 | 6 | ▶ | use XML::SAX::Exception; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 19 | |||||||||||
| 20 | # setup an exception class for validation errors | ||||||||||
| 21 | 6 | @XML::SAX::Exception::Validator::ISA = qw(XML::SAX::Exception); | |||||||||
| 22 | |||||||||||
| 23 | 6 | ▶ | use constant XSD => 'http://www.w3.org/2001/XMLSchema'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 24 | |||||||||||
| 25 | # get an attribute value by name, ignoring namespaces | ||||||||||
| 26 | 1915 | ▶ | sub _attr { | ||||||||
|
Subroutine
_attr: called CC=4 SCAR=13.9
| |||||||||||
| 27 | 1915 | my ($data, $name) = @_; | |||||||||
| 28 | return $data->{Attributes}{'{}' . $name}{Value} | ||||||||||
| 29 | 1915 | ▶ | if exists $data->{Attributes}{'{}' . $name}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 30 | 1155 | foreach my $attr (keys %{$data->{Attributes}}) { | |||||||||
| 31 | 1428 | ▶ | return $data->{$attr}->{Value} if $attr =~ /^\{.*?\}$name/; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 32 | } | ||||||||||
| 33 | 1155 | return; | |||||||||
| 34 | } | ||||||||||
| 35 | |||||||||||
| 36 | # throw a validator exception | ||||||||||
| 37 | 91 | ▶ | sub _err { | ||||||||
|
Subroutine
_err: called CC=1 SCAR=0.0
| |||||||||||
| 38 | 91 | XML::SAX::Exception::Validator->throw(Message => shift); | |||||||||
| 39 | } | ||||||||||
| 40 | |||||||||||
| 41 | |||||||||||
| 42 | |||||||||||
| 43 | 6 | 1; | |||||||||