File Coverage

blib/lib/Data/Rx/Type/Perl/Obj.pm
Criterion Covered Total %
statement 29 32 90.6
branch 6 8 75.0
condition 5 11 45.4
subroutine 8 8 100.0
pod 0 3 0.0
total 48 62 77.4


line stmt bran cond sub pod time code
1 1     1   4 use strict;
  1         1  
  1         27  
2 1     1   3 use warnings;
  1         1  
  1         39  
3             package Data::Rx::Type::Perl::Obj;
4             {
5             $Data::Rx::Type::Perl::Obj::VERSION = '0.009';
6             }
7             # ABSTRACT: experimental / perl object type
8 1     1   4 use parent 'Data::Rx::CommonType::EasyNew';
  1         1  
  1         3  
9              
10              
11 1     1   46 use Carp ();
  1         1  
  1         16  
12 1     1   4 use Scalar::Util ();
  1         1  
  1         280  
13              
14 1     1 0 23 sub type_uri { 'tag:codesimply.com,2008:rx/perl/obj' }
15              
16             sub guts_from_arg {
17 3     3 0 647 my ($class, $arg, $rx, $type) = @_;
18 3   50     11 $arg ||= {};
19              
20 3         17 for my $key (keys %$arg) {
21 3 50 33     18 next if $key eq 'isa' or $key eq 'does';
22 0         0 Carp::croak(
23             "unknown argument $key in constructing " . $class->type_uri . " type",
24             );
25             }
26              
27             return {
28 3         15 isa => $arg->{isa},
29             does => $arg->{does},
30             };
31             }
32              
33             sub assert_valid {
34 6     6 0 1428 my ($self, $value) = @_;
35              
36 6 100       21 unless (Scalar::Util::blessed($value)) {
37 2         22 $self->fail({
38             error => [ qw(type) ],
39             message => "found value is not blessed",
40             value => $value,
41             });
42             }
43              
44 4 100 66     18 if (defined $self->{isa} and not eval { $value->isa($self->{isa}) }) {
  4         37  
45 1         8 $self->fail({
46             error => [ qw(isa) ],
47             message => "found value is not isa $self->{isa}",
48             value => $value,
49             });
50             }
51              
52 3 50 33     9 if (defined $self->{does} and not eval { $value->DOES($self->{does}) }) {
  0         0  
53 0         0 $self->fail({
54             error => [ qw(does) ],
55             message => "found value does not do role $self->{does}",
56             value => $value,
57             });
58             }
59              
60 3         7 return 1;
61             }
62              
63             1;
64              
65             __END__