line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Class::Meta::Types::Perl; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=head1 NAME |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
Class::Meta::Types::Perl - Perl data types |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 SYNOPSIS |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
package MyApp::Thingy; |
10
|
|
|
|
|
|
|
use strict; |
11
|
|
|
|
|
|
|
use Class::Meta; |
12
|
|
|
|
|
|
|
use Class::Meta::Types::Perl; |
13
|
|
|
|
|
|
|
# OR... |
14
|
|
|
|
|
|
|
# use Class::Meta::Types::Perl 'affordance'; |
15
|
|
|
|
|
|
|
# OR... |
16
|
|
|
|
|
|
|
# use Class::Meta::Types::Perl 'semi-affordance'; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
BEGIN { |
19
|
|
|
|
|
|
|
# Create a Class::Meta object for this class. |
20
|
|
|
|
|
|
|
my $cm = Class::Meta->new( key => 'thingy' ); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# Add an integer attribute. |
23
|
|
|
|
|
|
|
$cm->add_attribute( name => 'my_hash', |
24
|
|
|
|
|
|
|
type => 'hash' ); |
25
|
|
|
|
|
|
|
$cm->build; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=head1 DESCRIPTION |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
This module provides Perl data types for use with Class::Meta attributes. |
31
|
|
|
|
|
|
|
Simply load it, then pass the name of one of its types to the |
32
|
|
|
|
|
|
|
C method of a Class::Meta object. See |
33
|
|
|
|
|
|
|
L for more information on using and |
34
|
|
|
|
|
|
|
creating data types. |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
The validation checks for Class::Meta::Types::Perl are provided by the |
37
|
|
|
|
|
|
|
Class::Meta::Type's support for object type validation, since Perl data types |
38
|
|
|
|
|
|
|
are understood by C. |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
The data types created by Class::Meta::Types::Perl are: |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=over |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=item scalar |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
A simple scalar value. This can be anything, and has no validation checks. |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=item scalarref |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
A scalar reference. C must return 'SCALAR'. |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=item array |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=item arrayref |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
A array reference. C must return 'ARRAY'. |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=item hash |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=item hashref |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
A hash reference. C must return 'HASH'. |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=item code |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=item coderef |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=item closure |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
A code reference. Also known as a closure. C must return |
71
|
|
|
|
|
|
|
'CODE'. |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=back |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=cut |
76
|
|
|
|
|
|
|
|
77
|
8
|
|
|
8
|
|
12053
|
use strict; |
|
8
|
|
|
|
|
17
|
|
|
8
|
|
|
|
|
326
|
|
78
|
8
|
|
|
8
|
|
50
|
use Class::Meta::Type; |
|
8
|
|
|
|
|
16
|
|
|
8
|
|
|
|
|
2055
|
|
79
|
|
|
|
|
|
|
our $VERSION = '0.66'; |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub import { |
82
|
9
|
|
|
9
|
|
597
|
my ($pkg, $builder) = @_; |
83
|
9
|
|
100
|
|
|
58
|
$builder ||= 'default'; |
84
|
9
|
100
|
|
|
|
546
|
return if eval "Class::Meta::Type->new('array')"; |
85
|
|
|
|
|
|
|
|
86
|
8
|
|
|
|
|
55
|
Class::Meta::Type->add( |
87
|
|
|
|
|
|
|
key => "scalar", |
88
|
|
|
|
|
|
|
name => "Scalar", |
89
|
|
|
|
|
|
|
desc => "Scalar", |
90
|
|
|
|
|
|
|
builder => $builder, |
91
|
|
|
|
|
|
|
); |
92
|
|
|
|
|
|
|
|
93
|
8
|
|
|
|
|
36
|
Class::Meta::Type->add( |
94
|
|
|
|
|
|
|
key => "scalarref", |
95
|
|
|
|
|
|
|
name => "Scalar Reference", |
96
|
|
|
|
|
|
|
desc => "Scalar reference", |
97
|
|
|
|
|
|
|
builder => $builder, |
98
|
|
|
|
|
|
|
check => 'SCALAR', |
99
|
|
|
|
|
|
|
); |
100
|
|
|
|
|
|
|
|
101
|
8
|
|
|
|
|
32
|
Class::Meta::Type->add( |
102
|
|
|
|
|
|
|
key => "array", |
103
|
|
|
|
|
|
|
name => "Array Reference", |
104
|
|
|
|
|
|
|
desc => "Array reference", |
105
|
|
|
|
|
|
|
alias => 'arrayref', |
106
|
|
|
|
|
|
|
builder => $builder, |
107
|
|
|
|
|
|
|
check => 'ARRAY', |
108
|
|
|
|
|
|
|
); |
109
|
|
|
|
|
|
|
|
110
|
8
|
|
|
|
|
34
|
Class::Meta::Type->add( |
111
|
|
|
|
|
|
|
key => "hash", |
112
|
|
|
|
|
|
|
name => "Hash Reference", |
113
|
|
|
|
|
|
|
desc => "Hash reference", |
114
|
|
|
|
|
|
|
alias => 'hashref', |
115
|
|
|
|
|
|
|
builder => $builder, |
116
|
|
|
|
|
|
|
check => 'HASH', |
117
|
|
|
|
|
|
|
); |
118
|
|
|
|
|
|
|
|
119
|
8
|
|
|
|
|
43
|
Class::Meta::Type->add( |
120
|
|
|
|
|
|
|
key => "code", |
121
|
|
|
|
|
|
|
name => "Code Reference", |
122
|
|
|
|
|
|
|
desc => "Code reference", |
123
|
|
|
|
|
|
|
alias => [qw(coderef closure)], |
124
|
|
|
|
|
|
|
builder => $builder, |
125
|
|
|
|
|
|
|
check => 'CODE', |
126
|
|
|
|
|
|
|
); |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
1; |
130
|
|
|
|
|
|
|
__END__ |