| 1 | package XML::Validate::Base; | ||||||||||
| 2 | |||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 2 | ▶ | use vars qw($VERSION); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 2 | $VERSION = sprintf"%d.%03d", q$Revision: 1.9 $ =~ /: (\d+)\.(\d+)/; | |||||||||
| 7 | |||||||||||
| 8 | 0 | ▶ | sub new { | ||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 9 | 0 | die "XML::Validate::Base::new must be overridden. (XML::Validate::Base is an abstract class.)"; | |||||||||
| 10 | } | ||||||||||
| 11 | |||||||||||
| 12 | 0 | ▶ | sub validate { | ||||||||
|
Subroutine
validate: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 13 | 0 | die "XML::Validate::Base::validate must be overridden. (XML::Validate::Base is an abstract class.)"; | |||||||||
| 14 | } | ||||||||||
| 15 | |||||||||||
| 16 | 0 | ▶ | sub options { | ||||||||
|
Subroutine
options: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 17 | 0 | my $self = shift; | |||||||||
| 18 | 0 | return $self->{options}; | |||||||||
| 19 | } | ||||||||||
| 20 | |||||||||||
| 21 | 0 | ▶ | sub last_error { | ||||||||
|
Subroutine
last_error: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 22 | 0 | my $self = shift; | |||||||||
| 23 | 0 | return $self->{error}; | |||||||||
| 24 | } | ||||||||||
| 25 | |||||||||||
| 26 | 0 | ▶ | sub add_error { | ||||||||
|
Subroutine
add_error: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 27 | 0 | my $self = shift; | |||||||||
| 28 | 0 | my ($error) = @_; | |||||||||
| 29 | 0 | $self->{error} = $error; | |||||||||
| 30 | } | ||||||||||
| 31 | |||||||||||
| 32 | 0 | ▶ | sub clear_errors { | ||||||||
|
Subroutine
clear_errors: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 33 | 0 | my $self = shift; | |||||||||
| 34 | 0 | $self->{error} = undef; | |||||||||
| 35 | } | ||||||||||
| 36 | |||||||||||
| 37 | 0 | ▶ | sub set_options { | ||||||||
|
Subroutine
set_options: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 38 | 0 | my $self = shift; | |||||||||
| 39 | 0 | my ($supplied_options,$valid_options) = @_; | |||||||||
| 40 | 0 | foreach my $option (keys %{$supplied_options}) { | |||||||||
| 41 | 0 | ▶ | if (!_member($option,keys %{$valid_options})) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 42 | 0 | die "Unknown option: $option\n"; | |||||||||
| 43 | } | ||||||||||
| 44 | } | ||||||||||
| 45 | 0 | $self->{options} = {%{$valid_options},%{$supplied_options}}; | |||||||||
| 46 | } | ||||||||||
| 47 | |||||||||||
| 48 | 0 | ▶ | sub _member { | ||||||||
|
Subroutine
_member: not called CC=3 SCAR=24.8
| |||||||||||
| 49 | 0 | my ($search,@list) = @_; | |||||||||
| 50 | 0 | foreach my $item (@list) { | |||||||||
| 51 | 0 | ▶ | return 1 if $search eq $item; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 52 | } | ||||||||||
| 53 | 0 | return 0; | |||||||||
| 54 | } | ||||||||||
| 55 | |||||||||||
| 56 | 0 | ▶ | sub TRACE {} | ||||||||
|
Subroutine
TRACE: not called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 57 | 0 | ▶ | sub DUMP {} | ||||||||
|
Subroutine
DUMP: not called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 58 | |||||||||||
| 59 | 2 | 1; | |||||||||
| 60 | |||||||||||
| 61 | =head1 NAME | ||||||||||
| 62 | |||||||||||
| 63 | XML::Validate::Base - Abstract base class to be used by XML::Validate modules | ||||||||||
| 64 | |||||||||||
| 65 | =head1 SYNOPSIS | ||||||||||
| 66 | |||||||||||
| 67 | use XML::Validate::Base; | ||||||||||
| 68 | |||||||||||
| 69 | sub new { | ||||||||||
| 70 | ... override new ... | ||||||||||
| 71 | } | ||||||||||
| 72 | |||||||||||
| 73 | sub validate { | ||||||||||
| 74 | ... override validate ... | ||||||||||
| 75 | } | ||||||||||
| 76 | |||||||||||
| 77 | =head1 DESCRIPTION | ||||||||||
| 78 | |||||||||||
| 79 | XML::Validate::Base provides a base class with helpful subs for real | ||||||||||
| 80 | XML::Validate modules. | ||||||||||
| 81 | |||||||||||
| 82 | =head1 METHODS | ||||||||||
| 83 | |||||||||||
| 84 | =over | ||||||||||
| 85 | |||||||||||
| 86 | =item new(%options) | ||||||||||
| 87 | |||||||||||
| 88 | Constructs a new validator. This method must be overridden. | ||||||||||
| 89 | |||||||||||
| 90 | =item validate($xml) | ||||||||||
| 91 | |||||||||||
| 92 | Parses and validates $xml. Returns a true value on success, undef on | ||||||||||
| 93 | failure. This method must be overridden. | ||||||||||
| 94 | |||||||||||
| 95 | =item options | ||||||||||
| 96 | |||||||||||
| 97 | An accessor for the options hashref. | ||||||||||
| 98 | |||||||||||
| 99 | =item set_options($supplied_options,$valid_options) | ||||||||||
| 100 | |||||||||||
| 101 | Sets the options for the validator. $supplied_options and $valid_options are | ||||||||||
| 102 | hash refs containing respectively the options supplied to the constructor and | ||||||||||
| 103 | the valid options for validator along with their default values. | ||||||||||
| 104 | |||||||||||
| 105 | If the supplied options hash ref contains an option not listed in valid | ||||||||||
| 106 | options, this sub throws an exception. | ||||||||||
| 107 | |||||||||||
| 108 | =item last_error | ||||||||||
| 109 | |||||||||||
| 110 | Returns the error from the last validate call. This is a hash ref with the | ||||||||||
| 111 | following fields: | ||||||||||
| 112 | |||||||||||
| 113 | =over | ||||||||||
| 114 | |||||||||||
| 115 | =item * | ||||||||||
| 116 | |||||||||||
| 117 | message | ||||||||||
| 118 | |||||||||||
| 119 | =item * | ||||||||||
| 120 | |||||||||||
| 121 | line | ||||||||||
| 122 | |||||||||||
| 123 | =item * | ||||||||||
| 124 | |||||||||||
| 125 | column | ||||||||||
| 126 | |||||||||||
| 127 | =back | ||||||||||
| 128 | |||||||||||
| 129 | Note that the error gets cleared at the beginning of each C<validate> call. | ||||||||||
| 130 | |||||||||||
| 131 | =item add_error($error) | ||||||||||
| 132 | |||||||||||
| 133 | Stores $error for retrieval by last_error. $error should be a hash ref. | ||||||||||
| 134 | |||||||||||
| 135 | =item clear_errors | ||||||||||
| 136 | |||||||||||
| 137 | Clears any errors held by the validator. | ||||||||||
| 138 | |||||||||||
| 139 | =back | ||||||||||
| 140 | |||||||||||
| 141 | =head1 VERSION | ||||||||||
| 142 | |||||||||||
| 143 | $Revision: 1.9 $ on $Date: 2005/09/06 11:05:08 $ by $Author: johna $ | ||||||||||
| 144 | |||||||||||
| 145 | =head1 AUTHOR | ||||||||||
| 146 | |||||||||||
| 147 | Colin Robertson E<lt>cpan _at_ bbc _dot_ co _dot_ ukE<gt> | ||||||||||
| 148 | |||||||||||
| 149 | =head1 COPYRIGHT | ||||||||||
| 150 | |||||||||||
| 151 | (c) BBC 2005. This program is free software; you can redistribute it and/or modify it under the GNU GPL. | ||||||||||
| 152 | See the file COPYING in this distribution, or http://www.gnu.org/licenses/gpl.txt | ||||||||||
| 153 | |||||||||||
| 154 | =cut | ||||||||||