File Coverage

blib/lib/MooX/TypeTiny.pm
Criterion Covered Total %
statement 18 19 94.7
branch 3 4 75.0
condition n/a
subroutine 5 5 100.0
pod n/a
total 26 28 92.8


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