File Coverage

blib/lib/Data/Object/Float.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: Float Object for Perl 5
2             package Data::Object::Float;
3              
4 26     26   14605 use 5.010;
  26         86  
5              
6 26     26   128 use Scalar::Util 'blessed', 'looks_like_number';
  26         44  
  26         1799  
7 26     26   7952 use Data::Object 'deduce_deep', 'detract_deep', 'throw';
  26         65  
  26         1726  
8 26     26   7243 use Data::Object::Class 'with';
  26         75  
  26         241  
9              
10             with 'Data::Object::Role::Float';
11              
12             use overload (
13 26         246 'bool' => 'data',
14             '""' => 'data',
15             '~~' => 'data',
16             fallback => 1,
17 26     26   27200 );
  26         54  
18              
19             our $VERSION = '0.42'; # VERSION
20              
21             sub new {
22 34     34 0 32465 my $class = shift;
23 34         73 my $args = shift;
24 34         64 my $role = 'Data::Object::Role::Type';
25              
26 34 0 33     456 $args = $args->data if blessed($args)
      33        
27             and $args->can('does')
28             and $args->does($role);
29              
30 34         334 $args =~ s/^\+//; # not keen on this but ...
31              
32 34 50 33     638 throw 'Type Instantiation Error: Not a Float or Number'
      33        
33             unless defined($args) && !ref($args)
34             && looks_like_number($args);
35              
36 34         151 return bless \$args, $class;
37             }
38              
39             sub data {
40 43     43 0 4839 goto &detract;
41             }
42              
43             sub detract {
44 44     44 0 189 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__