line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MooseX::Types::LoadableClass; # git description: v0.013-12-g14cfc61 |
2
|
|
|
|
|
|
|
# ABSTRACT: ClassName type constraint with coercion to load the class. |
3
|
|
|
|
|
|
|
# KEYWORDS: moose types constraints class classes role roles module modules |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.014'; |
6
|
|
|
|
|
|
|
|
7
|
6
|
|
|
6
|
|
515142
|
use strict; |
|
6
|
|
|
|
|
11
|
|
|
6
|
|
|
|
|
167
|
|
8
|
6
|
|
|
6
|
|
25
|
use warnings; |
|
6
|
|
|
|
|
8
|
|
|
6
|
|
|
|
|
195
|
|
9
|
6
|
|
|
6
|
|
3038
|
use MooseX::Types -declare => [qw/ ClassName LoadableClass LoadableRole /]; |
|
6
|
|
|
|
|
2053681
|
|
|
6
|
|
|
|
|
36
|
|
10
|
6
|
|
|
6
|
|
25140
|
use MooseX::Types::Moose qw(Str RoleName), ClassName => { -as => 'MooseClassName' }; |
|
6
|
|
|
|
|
69701
|
|
|
6
|
|
|
|
|
67
|
|
11
|
6
|
|
|
6
|
|
25131
|
use Module::Runtime qw(is_module_name use_package_optimistically); |
|
6
|
|
|
|
|
8
|
|
|
6
|
|
|
|
|
49
|
|
12
|
6
|
|
|
6
|
|
386
|
use if MooseX::Types->VERSION >= 0.42, 'namespace::autoclean'; |
|
6
|
|
|
|
|
11
|
|
|
6
|
|
|
|
|
144
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
subtype LoadableClass, |
15
|
|
|
|
|
|
|
as Str, |
16
|
|
|
|
|
|
|
where { |
17
|
|
|
|
|
|
|
is_module_name($_) |
18
|
|
|
|
|
|
|
and use_package_optimistically($_) |
19
|
|
|
|
|
|
|
and MooseClassName->check($_) |
20
|
|
|
|
|
|
|
}; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
subtype LoadableRole, |
23
|
|
|
|
|
|
|
as Str, |
24
|
|
|
|
|
|
|
where { |
25
|
|
|
|
|
|
|
is_module_name($_) |
26
|
|
|
|
|
|
|
and use_package_optimistically($_) |
27
|
|
|
|
|
|
|
and RoleName->check($_) |
28
|
|
|
|
|
|
|
}; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# back compat |
32
|
|
|
|
|
|
|
coerce LoadableClass, from Str, via { $_ }; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
coerce LoadableRole, from Str, via { $_ }; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
__PACKAGE__->type_storage->{ClassName} |
37
|
|
|
|
|
|
|
= __PACKAGE__->type_storage->{LoadableClass}; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
40
|
|
|
|
|
|
|
1; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
__END__ |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=pod |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=encoding UTF-8 |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=head1 NAME |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
MooseX::Types::LoadableClass - ClassName type constraint with coercion to load the class. |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=head1 VERSION |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
version 0.014 |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head1 SYNOPSIS |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
package MyClass; |
59
|
|
|
|
|
|
|
use Moose; |
60
|
|
|
|
|
|
|
use MooseX::Types::LoadableClass qw/ LoadableClass /; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
has foobar_class => ( |
63
|
|
|
|
|
|
|
is => 'ro', |
64
|
|
|
|
|
|
|
required => 1, |
65
|
|
|
|
|
|
|
isa => LoadableClass, |
66
|
|
|
|
|
|
|
); |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
MyClass->new(foobar_class => 'FooBar'); # FooBar.pm is loaded or an |
69
|
|
|
|
|
|
|
# exception is thrown. |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head1 DESCRIPTION |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
use Moose::Util::TypeConstraints; |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
my $tc = subtype as ClassName; |
76
|
|
|
|
|
|
|
coerce $tc, from Str, via { Class::Load::load_class($_); $_ }; |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
I've written those three lines of code quite a lot of times, in quite |
79
|
|
|
|
|
|
|
a lot of places. |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
Now I don't have to. |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=for stopwords ClassName |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head1 TYPES EXPORTED |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head2 C<LoadableClass> |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
A normal class / package. |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head2 C<LoadableRole> |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
Like C<LoadableClass>, except the loaded package must be a L<Moose::Role>. |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head1 AUTHOR |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
Tomas Doran <bobtfish@bobtfish.net> |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head1 CONTRIBUTORS |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=for stopwords Karen Etheridge Dagfinn Ilmari MannsÃ¥ker Florian Ragwitz СеÑгей Романов |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=over 4 |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=item * |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
Karen Etheridge <ether@cpan.org> |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=item * |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
Dagfinn Ilmari Mannsåker <ilmari@ilmari.org> |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=item * |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
Florian Ragwitz <rafl@debian.org> |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=item * |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
СеÑгей Романов <sromanov@cpan.org> |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=back |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENCE |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
This software is copyright (c) 2010 by Infinity Interactive, Inc. |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
128
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=cut |