File Coverage

blib/lib/MooX/LvalueAttribute.pm
Criterion Covered Total %
statement 14 15 93.3
branch 4 6 66.6
condition 4 9 44.4
subroutine 2 2 100.0
pod n/a
total 24 32 75.0


line stmt bran cond sub pod time code
1             #
2             # This file is part of MooX-LvalueAttribute
3             #
4             # This software is copyright (c) 2013 by Damien "dams" Krotkine.
5             #
6             # This is free software; you can redistribute it and/or modify it under
7             # the same terms as the Perl 5 programming language system itself.
8             #
9             package MooX::LvalueAttribute;
10             {
11             $MooX::LvalueAttribute::VERSION = '0.16';
12             }
13 3     3   217717 use strictures 1;
  3         22  
  3         76  
14              
15             # ABSTRACT: Provides Lvalue accessors to Moo class attributes
16              
17             require Moo;
18             require Moo::Role;
19              
20             our %INJECTED_IN_ROLE;
21             our %INJECTED_IN_CLASS;
22              
23             sub import {
24 4     4   714 my $class = shift;
25 4         13 my $target = caller;
26              
27 4 100 66     59 if ($Moo::Role::INFO{$target} && $Moo::Role::INFO{$target}{is_role}) {
    50 33        
28              
29             # We are loaded from a Moo role
30 2   33     10 $Moo::Role::INFO{$target}{accessor_maker} ||= do {
31 2         18 require Method::Generate::Accessor;
32 2         22145 Method::Generate::Accessor->new
33             };
34 2         116 Moo::Role->apply_roles_to_object(
35             $Moo::Role::INFO{$target}{accessor_maker},
36             'Method::Generate::Accessor::Role::LvalueAttribute',
37             );
38 2         3146 $INJECTED_IN_ROLE{$target} = 1;
39              
40             } elsif ($Moo::MAKERS{$target} && $Moo::MAKERS{$target}{is_class}) {
41              
42             # We are loaded from a Moo class
43 2 50       9 if ( !$INJECTED_IN_CLASS{$target} ) {
44 2         13 Moo::Role->apply_roles_to_object(
45             Moo->_accessor_maker_for($target),
46             'Method::Generate::Accessor::Role::LvalueAttribute',
47             );
48 2         3859 $INJECTED_IN_CLASS{$target} = 1;
49             }
50             } else {
51 0           die "MooX::LvalueAttribute can only be used in Moo classes or Moo roles.";
52             }
53              
54             }
55              
56              
57             1;
58              
59             __END__