File Coverage

blib/lib/MooX/InsideOut/Role/GenerateAccessor.pm
Criterion Covered Total %
statement 16 21 76.1
branch n/a
condition n/a
subroutine 6 9 66.6
pod 0 1 0.0
total 22 31 70.9


line stmt bran cond sub pod time code
1             package MooX::InsideOut::Role::GenerateAccessor;
2 1     1   1375 use Hash::Util::FieldHash::Compat qw(fieldhash);
  1         2265  
  1         5  
3 1     1   69 use Sub::Quote qw(quotify);
  1         3  
  1         54  
4 1     1   5 use Moo::Role;
  1         2  
  1         9  
5              
6             fieldhash our %FIELDS;
7              
8             around generate_method => sub {
9             my $orig = shift;
10             my $self = shift;
11             # would like a better way to disable XS
12             local $Method::Generate::Accessor::CAN_HAZ_XS = 0;
13             #TODO: add Storable hooks
14             $self->$orig(@_);
15             };
16              
17             sub _generate_simple_get {
18 9     9   109 my ($self, $me, $name) = @_;
19 9         15 my $name_str = quotify $name;
20 9         31 $self->{captures}{'$MooX_InsideOut_FIELDS'} = \\%FIELDS;
21 9         23 "\$MooX_InsideOut_FIELDS->{${me}}->{${name_str}}";
22             }
23              
24             sub _generate_simple_has {
25 0     0   0 my ($self, $me, $name) = @_;
26 0         0 "exists " . $self->_generate_simple_get($me, $name);
27             }
28              
29             sub _generate_simple_clear {
30 0     0   0 my ($self, $me, $name) = @_;
31 0         0 "delete " . $self->_generate_simple_get($me, $name);
32             }
33              
34             sub _generate_core_set {
35 6     6   505 my ($self, $me, $name, $spec, $value) = @_;
36 6         10 $self->_generate_simple_get($me, $name) . " = ${value}";
37             }
38              
39             sub _generate_xs {
40 0     0   0 die "Can't generate XS accessors for inside out objects";
41             }
42              
43 1     1 0 193 sub default_construction_string { '\(my $s)' }
44              
45             1;