WDDX/Boolean.pm

filter: Statementstmt 14.2% 6 / 42 Branchbran 0.0% 0 / 18 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 13.3% 2 / 15 Podpod n/a totaltotal 10.6% 8 / 75 CC 10 SCAR 20.1
CC
10
Cov
10%
start_tag
20.0
new
12.0
as_javascript
6.0
CRAP 7.5
« WDDX/Array.pm ↑ Summary WDDX/String.pm »
1 #!/usr/bin/perl -w
2 #
3 # $Id: Boolean.pm,v 1.1.1.1 2003/10/28 16:04:37 andy Exp $
4 #
5 # This code is copyright 1999-2000 by Scott Guelich <scott@scripted.com>
6 # and is distributed according to the same conditions as Perl itself
7 # Please visit http://www.scripted.com/wddx/ for more information
8 #
9  
10 package WDDX::Boolean;
11  
12 # Auto-inserted by build scripts
13 $VERSION = "1.01";
14  
15 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 require WDDX;
19  
20 { my $i_hate_the_w_flag_sometimes = [
21 $WDDX::PACKET_HEADER,
22 $WDDX::PACKET_FOOTER,
23 $WDDX::Boolean::VERSION
24 ] }
25  
26 1;
27  
28  
29 #/-----------------------------------------------------------------------
30 # Public Methods
31 #
32  
33 0 ▶sub new {
Subroutine new: not called CC=3 SCAR=24.8
34 0 my( $class, $value ) = @_;
35
36 0 ▶ croak "You must supply a value when creating a new $class object\n"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 0 0
37 unless defined $value;
38
39 0 ▶ my $self = {
Branch: 1 branch
BranchTrueFalseTotal
$value ? : 0 0 0
40 value => $value ? 1 : "",
41 };
42
43 0 bless $self, $class;
44 0 return $self;
45 }
46  
47  
48 0 ▶sub type {
Subroutine type: not called CC=1 SCAR=6.9
49 0 return "boolean";
50 }
51  
52  
53 0 ▶sub as_packet {
Subroutine as_packet: not called CC=1 SCAR=6.9
54 0 my( $self ) = @_;
55 0 my $output = $WDDX::PACKET_HEADER .
56 $self->_serialize .
57 $WDDX::PACKET_FOOTER;
58 }
59  
60  
61 0 ▶sub as_scalar {
Subroutine as_scalar: not called CC=1 SCAR=6.9
62 0 my( $self ) = @_;
63 0 return $self->_deserialize;
64 }
65  
66  
67 0 ▶sub as_javascript {
Subroutine as_javascript: not called CC=2 SCAR=17.9
68 0 my( $self, $js_var ) = @_;
69 0 ▶ return "$js_var=" . ( $self->{value} ? 'true' : 'false' ) . ";";
Branch: 1 branch
BranchTrueFalseTotal
$self->{'value'} ? : 0 0 0
70 }
71  
72  
73 #/-----------------------------------------------------------------------
74 # Private Methods
75 #
76  
77 0 ▶sub is_parser {
Subroutine is_parser: not called CC=1 SCAR=6.9
78 0 return 0;
79 }
80  
81  
82 0 ▶sub _serialize {
Subroutine _serialize: not called CC=2 SCAR=17.9
83 0 my( $self ) = @_;
84 0 ▶ my $value = ( $self->{value} ? "true" : "false" );
Branch: 1 branch
BranchTrueFalseTotal
$self->{'value'} ? : 0 0 0
85 0 my $output = "<boolean value='$value'/>";
86 0 return $output;
87 }
88  
89  
90 0 ▶sub _deserialize {
Subroutine _deserialize: not called CC=1 SCAR=6.9
91 0 my( $self ) = @_;
92 0 return $self->{value};
93 }
94  
95  
96 #/-----------------------------------------------------------------------
97 # Parsing Code
98 #
99  
100 package WDDX::Boolean::Parser;
101  
102  
103 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
104 0 return bless { value => undef }, shift;
105 }
106  
107  
108 0 ▶sub start_tag {
Subroutine start_tag: not called CC=4 SCAR=30.0
109 0 my( $self, $element, $attribs ) = @_;
110
111 0 ▶ if ( $element eq "boolean" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($element eq 'boolean') { } 0 0 0
112 0 ▶ if ( $attribs->{value} eq "true" ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($attribs->{'value'} eq 'true') { } 0 0 0
elsif ($attribs->{'value'} eq 'false') { } 0 0 0
113 0 $self->{value} = 1;
114 }
115 elsif ( $attribs->{value} eq "false" ) {
116 0 $self->{value} = "";
117 }
118 else {
119 0 die "Invalid value for value attribute in <boolean> tag";
120 }
121 }
122 else {
123 0 die "<$element> not allowed within <boolean> element\n";
124 }
125
126 0 return $self;
127 }
128  
129  
130 0 ▶sub end_tag {
Subroutine end_tag: not called CC=2 SCAR=17.9
131 0 my( $self, $element ) = @_;
132
133 0 ▶ if ( $element eq "boolean" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($element eq 'boolean') { } 0 0 0
134 0 $self = new WDDX::Boolean( $self->{value} );
135 }
136 else {
137 0 die "</$element> not allowed within <boolean> element\n";
138 }
139 0 return $self;
140 }
141  
142  
143 0 ▶sub append_data {
Subroutine append_data: not called CC=2 SCAR=17.9
144 0 my( $self, $data ) = @_;
145 0 ▶ die "No data is allowed between <boolean> tags\n" if $data =~ /\S/;
Branch: 1 branch
BranchTrueFalseTotal
if $data =~ /\S/ 0 0 0
146 }
147  
148  
149 0 ▶sub is_parser {
Subroutine is_parser: not called CC=1 SCAR=6.9
150 0 return 1;
151 }
152  
« WDDX/Array.pm ↑ Summary WDDX/String.pm »