File Coverage

blib/lib/MooX/Readonly/Attribute.pm
Criterion Covered Total %
statement 29 29 100.0
branch 3 4 75.0
condition n/a
subroutine 7 7 100.0
pod n/a
total 39 40 97.5


line stmt bran cond sub pod time code
1             package MooX::Readonly::Attribute;
2              
3 2     2   275469 use 5.006; use strict; use warnings; our $VERSION = '1.00';
  2     2   9  
  2     2   12  
  2         4  
  2         70  
  2         8  
  2         3  
  2         152  
4 2     2   926 use Const::XS qw/make_readonly/;
  2         1128  
  2         73  
5 2     2   1058 use MooX::ReturnModifiers;
  2         1461  
  2         494  
6              
7             sub import {
8 2     2   20 my $target = caller;
9 2         9 my %modifiers = return_modifiers( $target, [qw/before around/] );
10             $modifiers{around}->(
11             'has',
12             sub {
13 3     3   209193 my ( $orig, $attr, %opts ) = @_;
14 3 50       16 if (delete $opts{readonly}) {
15 3 100       11 if ($opts{coerce}) {
16 1         4 my $coerce = $opts{coerce};
17 1         7 $opts{coerce} = sub { my $val = $coerce->(@_); make_readonly($val); $val };
  2         2137  
  2         50  
  2         57  
18             } else {
19 2         11 $opts{coerce} = sub { make_readonly($_[0]); $_[0] };
  4         12443  
  4         106  
20             }
21             }
22 3         21 $orig->( $attr, %opts );
23             }
24 2         76 );
25             }
26             1;
27              
28              
29             1;
30              
31             __END__