File Coverage

lib/Spreadsheet/Engine/Value.pm
Criterion Covered Total %
statement 21 23 91.3
branch n/a
condition n/a
subroutine 9 10 90.0
pod 7 7 100.0
total 37 40 92.5


line stmt bran cond sub pod time code
1             package Spreadsheet::Engine::Value;
2              
3             =head1 NAME
4              
5             Spreadsheet::Engine::Value - A value/type combination
6              
7             =head1 SYNOPSIS
8              
9             my $op = Spreadsheet::Engine::Value->new(
10             type => 'n',
11             value => 10,
12             );
13              
14             my $type = $op->type;
15             my $value = $op->value;
16              
17             if ($op->is_txt) { ... }
18             if ($op->is_num) { ... }
19             if ($op->is_number) { ... }
20             if ($op->is_blank) { ... }
21             if ($op->is_logical) { ... }
22             if ($op->is_error) { ... }
23             if ($op->is_na) { ... }
24              
25             =head1 DESCRIPTION
26              
27             In a spreadsheet, values also have an accompanying type. This class
28             represents such a value/type combination.
29              
30             =cut
31              
32 28     28   164 use strict;
  28         59  
  28         1088  
33 28     28   160 use warnings;
  28         71  
  28         991  
34              
35             =head1 CONSTRUCTOR
36              
37             =head2 new
38              
39             Instantiate with a type and value.
40              
41             =head1 INSTANCE VARIABLES
42              
43             =head2 type / value
44              
45             The value and type.
46              
47             =cut
48              
49 28     28   157 use Class::Struct;
  28         60  
  28         162  
50             struct type => '$', value => '$';
51              
52             =head1 METHODS
53              
54             =head2 is_txt
55              
56             Does this have a textual type (of any subtype)?
57              
58             =cut
59              
60             sub is_txt {
61 855     855 1 2702 my $self = shift;
62 855         21239 substr($self->type, 0, 1) eq 't';
63             }
64              
65             =head2 is_num
66              
67             Does this have a numberic type (of any subtype)?
68              
69             =cut
70              
71             sub is_num {
72 14960     14960 1 21165 my $self = shift;
73 14960         313981 substr($self->type, 0, 1) eq 'n';
74             }
75              
76             =head2 is_number
77              
78             Is this a number (type 'n', no subtype)?
79              
80             =cut
81              
82             sub is_number {
83 0     0 1 0 my $self = shift;
84 0         0 $self->type eq 'n';
85             }
86              
87             =head2 is_blank
88              
89             Is this blank?
90              
91             =cut
92              
93             sub is_blank {
94 1403     1403 1 14914 my $self = shift;
95 1403         33661 $self->type eq 'b';
96             }
97              
98             =head2 is_logical
99              
100             Is this a logical value (true/false)?
101              
102             =cut
103              
104             sub is_logical {
105 45     45 1 1000 my $self = shift;
106 45         879 $self->type eq 'nl';
107             }
108              
109             =head2 is_error
110              
111             Is this an error?
112              
113             =cut
114              
115             sub is_error {
116 22670     22670 1 47867 my $self = shift;
117 22670         466924 substr($self->type, 0, 1) eq 'e';
118             }
119              
120             =head2 is_na
121              
122             Is this N/A?
123              
124             =cut
125              
126             sub is_na {
127 305     305 1 5313 my $self = shift;
128 305         6249 $self->type eq 'e#N/A';
129             }
130              
131             1;
132              
133             =head1 HISTORY
134              
135             This code was created for Spreadsheet::Engine 0.11
136              
137             =head1 COPYRIGHT
138              
139             Copyright (c) 2007, 2008 Tony Bowden
140              
141             =head1 LICENCE
142              
143             The contents of this file are subject to the Artistic License 2.0;
144             you may not use this file except in compliance with the License.
145             You may obtain a copy of the License at
146             http://www.perlfoundation.org/artistic_license_2_0
147              
148             =cut
149