File Coverage

blib/lib/Data/Object/Integer.pm
Criterion Covered Total %
statement 23 23 100.0
branch 1 4 25.0
condition 4 12 33.3
subroutine 8 8 100.0
pod 0 3 0.0
total 36 50 72.0


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