blib/lib/XML/LibXML/Number.pm

filter: Statementstmt 77.2% 34 / 44 Branchbran 30.0% 3 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 68.7% 11 / 16 Podpod 20.0% 2 / 10 totaltotal 62.5% 50 / 80 CC 6 SCAR 8.8
CC
6
Cov
69%
as_xml
6.0
to_boolean
6.0
cmp
2.1
CRAP 2.4
« blib/lib/XML/LibXML/SAX.pm ↑ Summary blib/lib/XML/LibXML/Literal.pm »
1 # $Id$
2 #
3 # This is free software, you may use it and distribute it under the same terms as
4 # Perl itself.
5 #
6 # Copyright 2001-2003 AxKit.com Ltd., 2002-2006 Christian Glahn, 2006-2009 Petr Pajas
7 #
8 #
9  
10 package XML::LibXML::Number;
11 69 ▶use XML::LibXML::Boolean;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 69 ▶use XML::LibXML::Literal;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 69 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 69 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 69 ▶use vars qw ($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
17 69 $VERSION = "2.0210"; # VERSION TEMPLATE: DO NOT CHANGE
18  
19 use overload
20 69 '""' => \&value,
21 '0+' => \&value,
22 69 ▶ '<=>' => \&cmp;
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 sub new {
25 27 ▶ my $class = shift;
Subroutine new: called CC=2 SCAR=7.2
Pod documented
26 27 my $number = shift;
27 27 ▶ if ($number !~ /^\s*(-\s*)?(\d+(\.\d*)?|\.\d+)\s*$/) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $number =~ /^\s*(-\s*)?(\d+(\.\d*)?|\.\d+)\s*$/) { } 0 27 27
28 0 $number = undef;
29 }
30 else {
31 27 $number =~ s/\s+//g;
32 }
33 27 bless \$number, $class;
34 }
35  
36 sub as_string {
37 22 ▶ my $self = shift;
Subroutine as_string: called CC=2 SCAR=7.2
Pod undocumented
38 22 ▶ defined $$self ? $$self : 'NaN';
Branch: 1 branch
BranchTrueFalseTotal
defined $$self ? : 22 0 22
39 }
40  
41 sub as_xml {
42 0 ▶ my $self = shift;
Subroutine as_xml: not called CC=2 SCAR=17.9
Pod undocumented
43 0 ▶ return "<Number>" . (defined($$self) ? $$self : 'NaN') . "</Number>\n";
Branch: 1 branch
BranchTrueFalseTotal
defined $$self ? : 0 0 0
44 }
45  
46 sub value {
47 3 ▶ my $self = shift;
Subroutine value: called CC=1 SCAR=0.0
Pod documented
48 3 $$self;
49 }
50  
51 sub cmp {
52 1 ▶ my $self = shift;
Subroutine cmp: called CC=2 SCAR=7.4
Pod undocumented
53 1 my ($other, $swap) = @_;
54 1 ▶ if ($swap) {
Branch: 1 branch
BranchTrueFalseTotal
if ($swap) 0 1 1
55 0 return $other <=> $$self;
56 }
57 1 return $$self <=> $other;
58 }
59  
60 sub evaluate {
61 0 ▶ my $self = shift;
Subroutine evaluate: not called CC=1 SCAR=6.9
Pod undocumented
62 0 $self;
63 }
64  
65 sub to_boolean {
66 0 ▶ my $self = shift;
Subroutine to_boolean: not called CC=2 SCAR=17.9
Pod undocumented
67 0 ▶ return $$self ? XML::LibXML::Boolean->True : XML::LibXML::Boolean->False;
Branch: 1 branch
BranchTrueFalseTotal
$$self ? : 0 0 0
68 }
69  
70 22 ▶sub to_literal { XML::LibXML::Literal->new($_[0]->as_string); }
Subroutine to_literal: called CC=1 SCAR=0.0
Pod undocumented
71 0 ▶sub to_number { $_[0]; }
Subroutine to_number: not called CC=1 SCAR=6.9
Pod undocumented
72  
73 0 ▶sub string_value { return $_[0]->value }
Subroutine string_value: not called CC=1 SCAR=6.9
Pod undocumented
74  
75 69 1;
76 __END__
« blib/lib/XML/LibXML/SAX.pm ↑ Summary blib/lib/XML/LibXML/Literal.pm »