line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
28
|
|
2
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
38
|
|
3
|
|
|
|
|
|
|
package Data::Rx::Type::Perl::Obj 0.010; |
4
|
|
|
|
|
|
|
# ABSTRACT: experimental / perl object type |
5
|
1
|
|
|
1
|
|
14
|
use parent 'Data::Rx::CommonType::EasyNew'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
7
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
#pod =head1 SYNOPSIS |
8
|
|
|
|
|
|
|
#pod |
9
|
|
|
|
|
|
|
#pod use Data::Rx; |
10
|
|
|
|
|
|
|
#pod use Data::Rx::Type::Perl::Obj; |
11
|
|
|
|
|
|
|
#pod use Test::More tests => 2; |
12
|
|
|
|
|
|
|
#pod |
13
|
|
|
|
|
|
|
#pod my $rx = Data::Rx->new({ |
14
|
|
|
|
|
|
|
#pod prefix => { |
15
|
|
|
|
|
|
|
#pod perl => 'tag:codesimply.com,2008:rx/perl/', |
16
|
|
|
|
|
|
|
#pod }, |
17
|
|
|
|
|
|
|
#pod type_plugins => [ 'Data::Rx::Type::Perl::Obj' ] |
18
|
|
|
|
|
|
|
#pod }); |
19
|
|
|
|
|
|
|
#pod |
20
|
|
|
|
|
|
|
#pod my $isa_rx = $rx->make_schema({ |
21
|
|
|
|
|
|
|
#pod type => '/perl/obj', |
22
|
|
|
|
|
|
|
#pod isa => 'Data::Rx', |
23
|
|
|
|
|
|
|
#pod }); |
24
|
|
|
|
|
|
|
#pod |
25
|
|
|
|
|
|
|
#pod ok($isa_rx->check($rx), "a Data::Rx object isa Data::Rx /perl/obj"); |
26
|
|
|
|
|
|
|
#pod ok(! $isa_rx->check( 1 ), "1 is not a Data::Rx /perl/obj"); |
27
|
|
|
|
|
|
|
#pod |
28
|
|
|
|
|
|
|
#pod =head1 ARGUMENTS |
29
|
|
|
|
|
|
|
#pod |
30
|
|
|
|
|
|
|
#pod "isa" and "does" ensure that the object passes the relevant test for the |
31
|
|
|
|
|
|
|
#pod identifier given. |
32
|
|
|
|
|
|
|
#pod |
33
|
|
|
|
|
|
|
#pod =cut |
34
|
|
|
|
|
|
|
|
35
|
1
|
|
|
1
|
|
67
|
use Carp (); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
10
|
|
36
|
1
|
|
|
1
|
|
11
|
use Scalar::Util (); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
267
|
|
37
|
|
|
|
|
|
|
|
38
|
1
|
|
|
1
|
0
|
16
|
sub type_uri { 'tag:codesimply.com,2008:rx/perl/obj' } |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub guts_from_arg { |
41
|
3
|
|
|
3
|
0
|
520
|
my ($class, $arg, $rx, $type) = @_; |
42
|
3
|
|
50
|
|
|
9
|
$arg ||= {}; |
43
|
|
|
|
|
|
|
|
44
|
3
|
|
|
|
|
7
|
for my $key (keys %$arg) { |
45
|
3
|
50
|
33
|
|
|
11
|
next if $key eq 'isa' or $key eq 'does'; |
46
|
0
|
|
|
|
|
0
|
Carp::croak( |
47
|
|
|
|
|
|
|
"unknown argument $key in constructing " . $class->type_uri . " type", |
48
|
|
|
|
|
|
|
); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
return { |
52
|
|
|
|
|
|
|
isa => $arg->{isa}, |
53
|
|
|
|
|
|
|
does => $arg->{does}, |
54
|
3
|
|
|
|
|
11
|
}; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub assert_valid { |
58
|
6
|
|
|
6
|
0
|
929
|
my ($self, $value) = @_; |
59
|
|
|
|
|
|
|
|
60
|
6
|
100
|
|
|
|
22
|
unless (Scalar::Util::blessed($value)) { |
61
|
2
|
|
|
|
|
14
|
$self->fail({ |
62
|
|
|
|
|
|
|
error => [ qw(type) ], |
63
|
|
|
|
|
|
|
message => "found value is not blessed", |
64
|
|
|
|
|
|
|
value => $value, |
65
|
|
|
|
|
|
|
}); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
4
|
100
|
66
|
|
|
16
|
if (defined $self->{isa} and not eval { $value->isa($self->{isa}) }) { |
|
4
|
|
|
|
|
42
|
|
69
|
1
|
|
|
|
|
7
|
$self->fail({ |
70
|
|
|
|
|
|
|
error => [ qw(isa) ], |
71
|
|
|
|
|
|
|
message => "found value is not isa $self->{isa}", |
72
|
|
|
|
|
|
|
value => $value, |
73
|
|
|
|
|
|
|
}); |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
3
|
50
|
33
|
|
|
14
|
if (defined $self->{does} and not eval { $value->DOES($self->{does}) }) { |
|
0
|
|
|
|
|
0
|
|
77
|
0
|
|
|
|
|
0
|
$self->fail({ |
78
|
|
|
|
|
|
|
error => [ qw(does) ], |
79
|
|
|
|
|
|
|
message => "found value does not do role $self->{does}", |
80
|
|
|
|
|
|
|
value => $value, |
81
|
|
|
|
|
|
|
}); |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
3
|
|
|
|
|
8
|
return 1; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
1; |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
__END__ |