File Coverage

blib/lib/Data/Object/Integer.pm
Criterion Covered Total %
statement 27 27 100.0
branch 2 4 50.0
condition 4 12 33.3
subroutine 9 9 100.0
pod 0 3 0.0
total 42 55 76.3


line stmt bran cond sub pod time code
1             # ABSTRACT: An Integer Object for Perl 5
2             package Data::Object::Integer;
3              
4 15     15   985 use 5.010;
  15         62  
  15         597  
5              
6 15     15   70 use Carp 'confess';
  15         18  
  15         1035  
7 15     15   74 use Scalar::Util 'blessed', 'looks_like_number';
  15         24  
  15         794  
8 15     15   470 use Data::Object 'deduce_deep', 'detract_deep';
  15         22  
  15         762  
9 15     15   408 use Data::Object::Class 'with';
  15         49  
  15         141  
10              
11             with 'Data::Object::Role::Integer';
12              
13             use overload (
14 15         125 'bool' => 'data',
15             '""' => 'data',
16             '~~' => 'data',
17             fallback => 1,
18 15     15   5790 );
  15         22  
19              
20             our $VERSION = '0.20'; # VERSION
21              
22             sub new {
23 37     37 0 1811 my $class = shift;
24 37         56 my $data = shift;
25              
26 37         80 $data =~ s/^\+//; # not keen on this but ...
27              
28 37   33     157 $class = ref($class) || $class;
29 37 50 33     146 unless (blessed($data) && $data->isa($class)) {
30 37 50 33     302 confess 'Type Instantiation Error: Not an Integer'
      33        
31             unless defined($data) && !ref($data)
32             && looks_like_number($data);
33             }
34              
35 37         208 return bless \$data, $class;
36             }
37              
38             sub data {
39 22     22 0 9460 goto &detract;
40             }
41              
42             sub detract {
43 22     22 0 69 return detract_deep shift;
44             }
45              
46             around 'downto' => sub {
47             my ($orig, $self, @args) = @_;
48             my $result = $self->$orig(@args);
49             return scalar deduce_deep $result;
50             };
51              
52             around 'eq' => sub {
53             my ($orig, $self, @args) = @_;
54             my $result = $self->$orig(@args);
55             return scalar deduce_deep $result;
56             };
57              
58             around 'gt' => sub {
59             my ($orig, $self, @args) = @_;
60             my $result = $self->$orig(@args);
61             return scalar deduce_deep $result;
62             };
63              
64             around 'gte' => sub {
65             my ($orig, $self, @args) = @_;
66             my $result = $self->$orig(@args);
67             return scalar deduce_deep $result;
68             };
69              
70             around 'lt' => sub {
71             my ($orig, $self, @args) = @_;
72             my $result = $self->$orig(@args);
73             return scalar deduce_deep $result;
74             };
75              
76             around 'lte' => sub {
77             my ($orig, $self, @args) = @_;
78             my $result = $self->$orig(@args);
79             return scalar deduce_deep $result;
80             };
81              
82             around 'ne' => sub {
83             my ($orig, $self, @args) = @_;
84             my $result = $self->$orig(@args);
85             return scalar deduce_deep $result;
86             };
87              
88             around 'to' => sub {
89             my ($orig, $self, @args) = @_;
90             my $result = $self->$orig(@args);
91             return scalar deduce_deep $result;
92             };
93              
94             around 'upto' => sub {
95             my ($orig, $self, @args) = @_;
96             my $result = $self->$orig(@args);
97             return scalar deduce_deep $result;
98             };
99              
100             1;
101              
102             __END__