lib/XML/Schema/Facet.pm

filter: Statementstmt 100% 44 / 44 Branchbran 75.0% 6 / 8 Conditioncond 87.5% 7 / 8 MC/DCmcdc 60.0% 3 / 5 Subroutinesub 100% 12 / 12 Podpod 22.2% 2 / 9 totaltotal 86.0% 74 / 86 CC 7 SCAR 7.5
CC
7
Cov
95%
init
4.0
new
3.0
invalid
2.0
CRAP 2.1
« lib/XML/Schema/Type.pm ↑ Summary blib/lib/XML/Schema/Annotation.pm »
1 #============================================================= -*-perl-*-
2 #
3 # XML::Schema::Facet
4 #
5 # DESCRIPTION
6 # Module implementing a base object class for representing XML
7 # Schema facets. A facet is a mechanism for specifying optional
8 # properties which constrain the value space of a datatype.
9 #
10 # AUTHOR
11 # Andy Wardley <abw@kfs.org>
12 #
13 # COPYRIGHT
14 # Copyright (C) 2001 Canon Research Centre Europe Ltd.
15 # All Rights Reserved.
16 #
17 # This module is free software; you can redistribute it and/or
18 # modify it under the same terms as Perl itself.
19 #
20 # REVISION
21 # $Id: Facet.pm,v 1.1.1.1 2001/08/29 14:30:17 abw Exp $
22 #
23 #========================================================================
24  
25 package XML::Schema::Facet;
26  
27 28 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 28 ▶use base qw( XML::Schema::Base );
Subroutine BEGIN: called CC=1 SCAR=0.0
29 28 ▶use vars qw( $VERSION $DEBUG $ERROR @MANDATORY @OPTIONAL );
Subroutine BEGIN: called CC=1 SCAR=0.0
30  
31 28 $VERSION = sprintf("%d.%02d", q$Revision: 1.1.1.1 $ =~ /(\d+)\.(\d+)/);
32 28 ▶$DEBUG = 0 unless defined $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $XML::Schema::Facet::DEBUG 28 0 28
33 28 $ERROR = '';
34  
35 28 @MANDATORY = qw( value );
36 28 @OPTIONAL = qw( annotation name errmsg );
37  
38  
39 #------------------------------------------------------------------------
40 # new()
41 #
42 # Specialised constructor which extracts the facet name from the last
43 # element of the package name. e.g. for XML:Schema::Facet::minLength
44 # the facet name is 'minLength'. The $NAME package variable may be
45 # defined to override this behaviour and specify an alternate facet
46 # name.
47 #------------------------------------------------------------------------
48  
49 302 ▶sub new {
Subroutine new: called CC=3 SCAR=11.0
Pod documented
50 302 my $class = shift;
51  
52 # make "new($n)" equivalent to "new(value => $n)"
53 302 ▶ unshift(@_, 'value') if @_ == 1 && ref $_[0] ne 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if @_ == 1 and ref $_[0] ne "HASH" 5 297 302
Condition100%3/3
@_ == 1 and ref $_[0] ne "HASH"
!ll&&!rl&&r
302675
MC/DC100%2/2
@_ == 1 and ref $_[0] ne "HASH"
@_ == 1 ref $_[0] ne "HASH"
Truth table100%3/3
A and B
A= @_ == 1B= ref $_[0] ne "HASH"
ABresult
0X0
100
111
54  
55 302 $class->SUPER::new(@_);
56 }
57  
58  
59 302 ▶sub init {
Subroutine init: called CC=4 SCAR=13.9
Pod documented
60 302 my ($self, $config) = @_;
61 302 my ($mand, $option) = @{ $self->_baseargs( qw( @MANDATORY %OPTIONAL ) ) };
62  
63 302 ▶ $self->_mandatory($mand, $config)
Branch: 1 branch
BranchTrueFalseTotal
$self->_mandatory($mand, $config) or return 299 3 302
64 || return;
65  
66 299 ▶ $self->_optional($option, $config)
Branch: 1 branch
BranchTrueFalseTotal
$self->_optional($option, $config) or return 299 0 299
67 || return;
68  
69 299 ▶ $self->{ name } ||= do {
Condition66%2/3
$self->{"name"} ||= do { my $class = ref $self; $class =~ /.*::(\w+)$/; $1 }
l!l&&r!l&&!r
12980
MC/DC0%0/2
$self->{"name"} ||= do { my $class = ref $self; $class =~ /.*::(\w+)$/; $1 }
$self->{"name"} do { my $class = ref $self; $class =~ /.*::(\w+)$/; $1 }
Truth table66%2/3
A ||= B
A= $self->{"name"}B= do { my $class = ref $self; $class =~ /.*::(\w+)$/; $1 }
ABresult
1X1
011
000
70 298 my $class = ref $self;
71 298 $class =~ /.*::(\w+)$/;
72 298 $1;
73 };
74  
75 299 return $self;
76 }
77  
78  
79 230 ▶sub install {
Subroutine install: called CC=1 SCAR=0.0
Pod undocumented
80 230 my ($self, $facets, $table) = @_;
81 # $self->DEBUG("installing $self into type as $self->{ name }\n");
82 230 push(@$facets, $self);
83 230 $table->{ $self->{ name } } = $self;
84 230 return 1;
85 }
86  
87 6 ▶sub name {
Subroutine name: called CC=1 SCAR=0.0
Pod undocumented
88 6 my $self = shift;
89 6 return $self->{ name };
90 }
91  
92 6 ▶sub value {
Subroutine value: called CC=1 SCAR=0.0
Pod undocumented
93 6 my $self = shift;
94 6 return $self->{ value };
95 }
96  
97 3 ▶sub annotation {
Subroutine annotation: called CC=1 SCAR=0.0
Pod undocumented
98 3 my $self = shift;
99 3 return $self->{ annotation };
100 }
101  
102 2 ▶sub valid {
Subroutine valid: called CC=1 SCAR=0.0
Pod undocumented
103 2 my ($self, $instance, $type) = @_;
104 2 return 1;
105 }
106  
107 61 ▶sub invalid {
Subroutine invalid: called CC=2 SCAR=6.9
Pod undocumented
108 61 my ($self, $msg) = @_;
109 $self->error($self->{ errmsg } ||
110 61 ▶ "$msg (required $self->{ name }: $self->{ value })");
Condition100%2/2
$self->{'errmsg'} || "$msg (required $self->{'name'}: $self->{'value'})"
l!l
1942
MC/DC100%1/1
$self->{'errmsg'} || "$msg (required $self->{'name'}: $self->{'value'})"
$self->{'errmsg'}
Truth table100%2/2
A
A= $self->{'errmsg'}
Aresult
11
00
111 }
112  
113  
114 1 ▶sub accept {
Subroutine accept: called CC=1 SCAR=0.0
Pod undocumented
115 1 my ($self, $visitor) = @_;
116 1 $visitor->visit_facet($self);
117 }
118  
119 28 1;
120  
121 __END__
« lib/XML/Schema/Type.pm ↑ Summary blib/lib/XML/Schema/Annotation.pm »