line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# $Id$ |
2
|
|
|
|
|
|
|
# $Source$ |
3
|
|
|
|
|
|
|
# $Author$ |
4
|
|
|
|
|
|
|
# $HeadURL$ |
5
|
|
|
|
|
|
|
# $Revision$ |
6
|
|
|
|
|
|
|
# $Date$ |
7
|
|
|
|
|
|
|
package Class::Dot::Meta::Type; |
8
|
|
|
|
|
|
|
|
9
|
16
|
|
|
45
|
|
91
|
use strict; |
|
16
|
|
|
|
|
29
|
|
|
16
|
|
|
|
|
584
|
|
10
|
16
|
|
|
45
|
|
83
|
use warnings; |
|
16
|
|
|
|
|
25
|
|
|
16
|
|
|
|
|
1924
|
|
11
|
16
|
|
|
45
|
|
77
|
use version; |
|
16
|
|
|
|
|
27
|
|
|
16
|
|
|
|
|
121
|
|
12
|
16
|
|
|
45
|
|
1261
|
use 5.00600; |
|
16
|
|
|
|
|
54
|
|
|
16
|
|
|
|
|
812
|
|
13
|
|
|
|
|
|
|
|
14
|
16
|
|
|
45
|
|
82
|
use Carp qw(croak); |
|
16
|
|
|
|
|
25
|
|
|
16
|
|
|
|
|
819
|
|
15
|
16
|
|
|
45
|
|
180
|
use Scalar::Util qw(blessed); |
|
16
|
|
|
|
|
41
|
|
|
16
|
|
|
|
|
734
|
|
16
|
|
|
|
|
|
|
|
17
|
16
|
|
|
16
|
|
80
|
use Class::Dot::Meta::Method qw(install_sub_from_class); |
|
16
|
|
|
|
|
27
|
|
|
16
|
|
|
|
|
108
|
|
18
|
|
|
|
|
|
|
|
19
|
16
|
|
|
16
|
|
1378
|
use Class::Dot::Devel::Sub::Name qw(subname); |
|
16
|
|
|
|
|
35
|
|
|
16
|
|
|
|
|
154
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
our $VERSION = qv('2.0.0_15'); |
22
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:ASKSH'; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
my %EXPORT_OK = map { $_ => 1 } qw( |
25
|
|
|
|
|
|
|
create_type_instance |
26
|
|
|
|
|
|
|
_NEWSCHOOL_TYPE _OLDSCHOOL_TYPE |
27
|
|
|
|
|
|
|
); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# All type classes inherits from this. |
30
|
|
|
|
|
|
|
my $TYPE_BASE_CLASS = 'Class::Dot::Type'; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub import { |
33
|
94
|
|
|
94
|
|
316
|
my ($this_class, @subs) = @_; |
34
|
94
|
|
|
|
|
235
|
my $caller_class = caller 0; |
35
|
|
|
|
|
|
|
|
36
|
94
|
|
|
|
|
747
|
for my $sub (@subs) { |
37
|
172
|
50
|
|
|
|
578
|
if (! exists $EXPORT_OK{$sub}) { |
38
|
0
|
|
|
|
|
0
|
croak "$sub is not exported by " . __PACKAGE__; |
39
|
|
|
|
|
|
|
} |
40
|
172
|
|
|
|
|
475
|
install_sub_from_class($this_class, $sub => $caller_class); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
94
|
|
|
|
|
33900
|
return; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub _NEWSCHOOL_TYPE { |
47
|
234
|
|
|
234
|
|
336
|
my ($type_var) = @_; |
48
|
234
|
100
|
|
|
|
1096
|
return if not blessed $type_var; |
49
|
195
|
100
|
|
|
|
896
|
return if not $type_var->isa($TYPE_BASE_CLASS); |
50
|
193
|
|
|
|
|
621
|
return 1; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub _OLDSCHOOL_TYPE { |
54
|
0
|
|
|
0
|
|
0
|
my ($type_var) = @_; |
55
|
0
|
0
|
|
|
|
0
|
return if not ref $type_var eq 'CODE'; |
56
|
0
|
|
|
|
|
0
|
return 1; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub create_type_instance { |
60
|
139
|
|
|
139
|
0
|
4215
|
my ($type, $isa, $constraint, $linear_isa_ref) = @_; |
61
|
|
|
|
|
|
|
$constraint = defined $constraint ? $constraint |
62
|
139
|
50
|
|
0
|
|
490
|
: sub { }; |
|
0
|
|
|
|
|
0
|
|
63
|
|
|
|
|
|
|
|
64
|
139
|
|
|
|
|
5035
|
my $metaclass = Class::Dot::Meta::Class->new(); |
65
|
|
|
|
|
|
|
|
66
|
139
|
|
|
|
|
425
|
my $full_class_name = $metaclass->subclass_name($TYPE_BASE_CLASS, $type); |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
$metaclass->create_class($full_class_name, { |
69
|
|
|
|
|
|
|
default_value => |
70
|
|
|
|
|
|
|
(subname "${full_class_name}::default_value" => sub { |
71
|
63
|
|
|
63
|
|
100
|
my ($self) = @_; |
|
|
|
|
63
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
|
33
|
|
|
|
72
|
63
|
|
|
|
|
319
|
my $sub_ref = $self->__isa__; |
73
|
63
|
|
|
|
|
234
|
return $sub_ref->(); |
74
|
139
|
|
|
|
|
2215
|
}), |
75
|
|
|
|
|
|
|
}, |
76
|
|
|
|
|
|
|
[ $TYPE_BASE_CLASS ], |
77
|
|
|
|
|
|
|
); |
78
|
|
|
|
|
|
|
|
79
|
139
|
|
|
|
|
1444
|
my $type_instance = $full_class_name->new({ |
80
|
|
|
|
|
|
|
type => $type, |
81
|
|
|
|
|
|
|
linear_isa => $linear_isa_ref, |
82
|
|
|
|
|
|
|
__isa__ => $isa, |
83
|
|
|
|
|
|
|
constraint => $constraint, |
84
|
|
|
|
|
|
|
}); |
85
|
|
|
|
|
|
|
|
86
|
139
|
|
|
|
|
902
|
return $type_instance; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
1; |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
__END__ |