File Coverage

blib/lib/MooX/ShortHas.pm
Criterion Covered Total %
statement 16 16 100.0
branch 2 2 100.0
condition n/a
subroutine 9 9 100.0
pod n/a
total 27 27 100.0


line stmt bran cond sub pod time code
1             package MooX::ShortHas;
2              
3 1     1   66649 use strictures 2;
  1         6  
  1         45  
4              
5             our $VERSION = '1.172300'; # VERSION
6              
7             # ABSTRACT: shortcuts for common Moo has attribute configurations
8              
9             #
10             # This file is part of MooX-ShortHas
11             #
12             #
13             # Christian Walde has dedicated the work to the Commons by waiving all of his
14             # or her rights to the work worldwide under copyright law and all related or
15             # neighboring legal rights he or she had in the work, to the extent allowable by
16             # law.
17             #
18             # Works under CC0 do not require attribution. When citing the work, you should
19             # not imply endorsement by the author.
20             #
21              
22              
23 1     1   229 use Moo::_Utils;
  1         2  
  1         211  
24              
25             sub _modified_has {
26 6     6   14 my ( $has, $mod, $name, @args ) = @_;
27 6         8 $has->( $name, @{$mod}, @args );
  6         16  
28             }
29              
30             sub import {
31 2     2   7458 my $caller = caller;
32 2 100       30 my $has = $caller->can( "has" ) or die "Moo not loaded in caller: $caller";
33             my %mods = (
34             lazy => [qw( is lazy builder )],
35 1         2 map { $_ => [ is => $_ => required => 1 ] } qw( ro rwp rw )
  3         9  
36             );
37 1         4 for my $mod ( keys %mods ) {
38             _install_coderef $caller. "::$mod" => sub {
39 6     6   18394 _modified_has $has, $mods{$mod}, @_;
        6      
        6      
        6      
        6      
40 4         57 };
41             }
42             }
43              
44             1;
45              
46             __END__