line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MooX::TypeTiny; |
2
|
5
|
|
|
5
|
|
670190
|
use strict; |
|
5
|
|
|
|
|
48
|
|
|
5
|
|
|
|
|
146
|
|
3
|
5
|
|
|
5
|
|
30
|
use warnings; |
|
5
|
|
|
|
|
17
|
|
|
5
|
|
|
|
|
281
|
|
4
|
|
|
|
|
|
|
our $VERSION = '0.002001'; |
5
|
|
|
|
|
|
|
$VERSION =~ tr/_//d; |
6
|
|
|
|
|
|
|
|
7
|
5
|
|
|
5
|
|
61
|
use Moo::_Utils qw(_install_modifier); |
|
5
|
|
|
|
|
22
|
|
|
5
|
|
|
|
|
836
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub import { |
10
|
5
|
|
|
5
|
|
51
|
my $target = caller; |
11
|
5
|
|
|
|
|
26
|
require Moo; |
12
|
5
|
|
|
|
|
2435
|
require Moo::Role; |
13
|
|
|
|
|
|
|
|
14
|
5
|
50
|
|
|
|
47752
|
unless (Moo->is_class($target)) { |
15
|
0
|
|
|
|
|
0
|
die "MooX::TypeTiny can only be used on Moo classes."; |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
_install_modifier($target, 'before', ['has', 'extends', 'with'], sub { |
19
|
10
|
|
|
10
|
|
278815
|
Moo::Role->apply_roles_to_object( |
20
|
|
|
|
|
|
|
Moo->_accessor_maker_for($target), |
21
|
|
|
|
|
|
|
'MooX::TypeTiny::Role::GenerateAccessor', |
22
|
|
|
|
|
|
|
); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
# make sure we have our own constructor |
25
|
10
|
|
|
|
|
12793
|
Moo->_constructor_maker_for($target); |
26
|
5
|
|
|
|
|
85
|
}); |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
1; |
30
|
|
|
|
|
|
|
__END__ |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=pod |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=encoding utf-8 |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=head1 NAME |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
MooX::TypeTiny - Optimized type checks for Moo + Type::Tiny |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head1 SYNOPSIS |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
package Some::Moo::Class; |
43
|
|
|
|
|
|
|
use Moo; |
44
|
|
|
|
|
|
|
use MooX::TypeTiny; |
45
|
|
|
|
|
|
|
use Types::Standard qw(Int); |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
has attr1 => (is => 'ro', isa => Int); |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=head1 DESCRIPTION |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
This module optimizes L<Moo> type checks when used with L<Type::Tiny> to perform |
52
|
|
|
|
|
|
|
better. It will automatically apply to isa checks and coercions that use |
53
|
|
|
|
|
|
|
Type::Tiny. Non-Type::Tiny isa checks will work as normal. |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
This is done by inlining the type check in a more optimal manner that is |
56
|
|
|
|
|
|
|
specific to Type::Tiny rather than the general mechanism Moo usually uses. |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
With this module, setters with type checks should be as fast as an equivalent |
59
|
|
|
|
|
|
|
check in L<Moose>. |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
It is hoped that eventually this type inlining will be done automatically, |
62
|
|
|
|
|
|
|
making this module unnecessary. |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=head1 AUTHOR |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
haarg - Graham Knop (cpan:HAARG) <haarg@haarg.org> |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=head1 CONTRIBUTORS |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
None so far. |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head1 COPYRIGHT |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
Copyright (c) 2015 the MooX::TypeTiny L</AUTHOR> and L</CONTRIBUTORS> |
75
|
|
|
|
|
|
|
as listed above. |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head1 LICENSE |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
This library is free software and may be distributed under the same terms |
80
|
|
|
|
|
|
|
as perl itself. See L<http://dev.perl.org/licenses/>. |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=cut |