File Coverage

blib/lib/MooX/TypeTiny.pm
Criterion Covered Total %
statement 17 18 94.4
branch 1 2 50.0
condition 2 2 100.0
subroutine 5 5 100.0
pod n/a
total 25 27 92.5


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