File Coverage

blib/lib/Data/Object/Undef.pm
Criterion Covered Total %
statement 22 22 100.0
branch 1 4 25.0
condition 2 6 33.3
subroutine 8 8 100.0
pod 0 3 0.0
total 33 43 76.7


line stmt bran cond sub pod time code
1             # ABSTRACT: Undef Object for Perl 5
2             package Data::Object::Undef;
3              
4 17     17   10278 use 5.010;
  17         54  
5              
6 17     17   94 use Scalar::Util 'blessed';
  17         27  
  17         1497  
7 17     17   3247 use Data::Object 'deduce_deep', 'detract_deep', 'throw';
  17         120  
  17         1259  
8 17     17   3710 use Data::Object::Class 'with';
  17         38  
  17         165  
9              
10             with 'Data::Object::Role::Undef';
11              
12             use overload (
13 17         155 'bool' => 'data',
14             '""' => 'data',
15             '~~' => 'data',
16             fallback => 1,
17 17     17   14908 );
  17         31  
18              
19             our $VERSION = '0.41'; # VERSION
20              
21             sub new {
22 18     18 0 10237 my $class = shift;
23 18         34 my $args = shift;
24 18         33 my $role = 'Data::Object::Role::Type';
25              
26 18 0 33     150 $args = $args->data if blessed($args)
      33        
27             and $args->can('does')
28             and $args->does($role);
29              
30 18 50       88 throw 'Type Instantiation Error: Not an Undefined value'
31             if defined $args;
32              
33 18         84 return bless \$args, $class;
34             }
35              
36             sub data {
37 10     10 0 2062 goto &detract;
38             }
39              
40             around 'defined' => sub {
41             my ($orig, $self, @args) = @_;
42             my $result = $self->$orig(@args);
43             return scalar deduce_deep $result;
44             };
45              
46             sub detract {
47 11     11 0 50 return detract_deep shift;
48             }
49              
50             1;
51              
52             __END__