File Coverage

blib/lib/Protocol/XMLRPC/Value/Integer.pm
Criterion Covered Total %
statement 23 23 100.0
branch 3 4 75.0
condition 5 5 100.0
subroutine 8 8 100.0
pod 4 5 80.0
total 43 45 95.5


line stmt bran cond sub pod time code
1             package Protocol::XMLRPC::Value::Integer;
2              
3 9     9   2167 use strict;
  9         16  
  9         298  
4 9     9   70 use warnings;
  9         78  
  9         242  
5              
6 9     9   46 use base 'Protocol::XMLRPC::Value';
  9         12  
  9         3464  
7              
8             sub new {
9 19     19 1 100 my $self = shift->SUPER::new(@_);
10              
11 19   100     93 $self->{alias} ||= 'i4';
12              
13 19         68 return $self;
14             }
15              
16             sub parse {
17 4     4 0 1141 my $class = shift;
18 4         8 my $string = shift;
19              
20 4 100 100     48 die "Invalid 'Integer' value"
21             unless defined $string && $string =~ m/^(?:\+|-)?\d+$/;
22              
23 1         5 return $class->new($string, @_);
24             }
25              
26 20 50   20 1 65 sub alias { defined $_[1] ? $_[0]->{alias} = $_[1] : $_[0]->{alias} }
27              
28 1     1 1 847 sub type {'int'}
29              
30             sub to_string {
31 20     20 1 46 my $self = shift;
32              
33 20         49 my $value = $self->value;
34              
35 20         28 $value = int($value);
36              
37 20         37 my $alias = $self->alias;
38 20         82 return "<$alias>$value";
39             }
40              
41             1;
42             __END__