DOM2/Attribute.pm

filter: Statementstmt 88.1% 37 / 42 Branchbran 33.3% 4 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 82.3% 14 / 17 Podpod 100% 9 / 9 totaltotal 80.0% 64 / 80 CC 7 SCAR 11.2
CC
7
Cov
76%
document
12.0
new
4.2
serialise_full
2.0
CRAP 3.1
« DOM2/Element/CDATA.pm ↑ Summary DOM2/Element/DocumentType.pm »
1 package XML::DOM2::Attribute;
2  
3 =head1 NAME
4  
5 XML::DOM2::Attribute
6  
7 =head1 DESCRIPTION
8  
9 Attribute object class for XML documents
10  
11 =head1 METHODS
12  
13 =cut
14  
15 4 ▶use base "XML::DOM2::DOM::Attribute";
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 4 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 use overload
22 4 ▶ '""' => sub { shift->auto_string( @_ ) },
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
23 1 ▶ 'eq' => sub { shift->auto_eq( @_ ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
24 0 ▶ 'ne' => sub { not shift->auto_eq( @_ ) };
Subroutine __ANON__: not called CC=1 SCAR=0.2
25  
26 =head2 $class->new( %options )
27  
28 Create a new Attribute object.
29  
30 =cut
31 sub new
32 8 ▶{
Subroutine new: called CC=4 SCAR=14.3
Pod documented
33 8 my ($proto, %opts) = @_;
34 8 ▶ croak "Attribute must have a name!" if not $opts{'name'};
Branch: 1 branch
BranchTrueFalseTotal
unless $opts{"name"} 0 8 8
35 8 ▶ croak "Attribute must have an owner" if not $opts{'owner'};
Branch: 1 branch
BranchTrueFalseTotal
unless $opts{"owner"} 0 8 8
36 8 my $value = delete($opts{'value'});
37 8 my $self = bless \%opts, $proto;
38 8 ▶ $self->deserialise( $value ) if defined($value);
Branch: 1 branch
BranchTrueFalseTotal
if defined $value 0 8 8
39 8 return $self;
40 }
41  
42 =head2 $attribute->value()
43  
44 Returns the serialised value within this attribute.
45  
46 =cut
47 sub value
48 9 ▶{
Subroutine value: called CC=1 SCAR=0.0
Pod documented
49 9 my ($self) = @_;
50 9 return $self->serialise;
51 }
52  
53 =head2 $attribute->serialise()
54  
55 Returns the serialised value for this attribute.
56  
57 =cut
58 sub serialise
59 9 ▶{
Subroutine serialise: called CC=1 SCAR=0.0
Pod documented
60 9 my ($self) = @_;
61 9 return $self->{'value'};
62 }
63  
64 =head2 $attribute->deserialise( $value )
65  
66 Sets the attribute value to $value, does any deserialisation too.
67  
68 =cut
69 sub deserialise
70 6 ▶{
Subroutine deserialise: called CC=1 SCAR=0.0
Pod documented
71 6 my ($self, $value) = @_;
72 6 $self->{'value'} = $value;
73 }
74  
75 =head2 $attribute->serialise_full()
76  
77 Returns the serialised name and value for this attribute.
78  
79 =cut
80 sub serialise_full
81 3 ▶{
Subroutine serialise_full: called CC=2 SCAR=7.0
Pod documented
82 3 my ($self) = @_;
83 3 my $value = $self->value;
84 3 ▶ $value = '~undef~' if not defined($value);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 3 3
85 3 return $self->name.'="'.$value.'"';
86 }
87  
88 =head2 $attribute->document()
89  
90 Return the document associated with this attribute.
91  
92 =cut
93 sub document
94 0 ▶{
Subroutine document: not called CC=3 SCAR=24.8
Pod documented
95 0 my ($self) = @_;
96 0 ▶ warn "No owner element\n" if not $self->ownerElement;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->ownerElement 0 0 0
97 0 ▶ return undef if not $self->ownerElement;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->ownerElement 0 0 0
98 0 return $self->ownerElement->document;
99 }
100  
101 =head2 $attribute->delete()
102  
103 Delete this attribute, NOT IMPLIMENTED.
104  
105 =cut
106 0 ▶sub delete {}
Subroutine delete: not called CC=1 SCAR=0.0
Pod documented
107  
108 =head1 OVERLOADED
109  
110 =head2 $object->auto_string()
111  
112 =cut
113 4 ▶sub auto_string { return shift->value() }
Subroutine auto_string: called CC=1 SCAR=0.0
Pod documented
114  
115 =head2 $object->auto_eq( $string )
116  
117 =cut
118 1 ▶sub auto_eq { return shift->value() eq shift }
Subroutine auto_eq: called CC=1 SCAR=0.0
Pod documented
119  
120 =head1 COPYRIGHT
121  
122 Martin Owens, doctormo@cpan.org
123  
124 =head1 SEE ALSO
125  
126 L<XML::DOM2>,L<XML::DOM2::DOM::Attribute>
127  
128 =cut
129 4 1;
« DOM2/Element/CDATA.pm ↑ Summary DOM2/Element/DocumentType.pm »