PrivateSetters/Role/Attribute.pm

filter: Statementstmt 100% 26 / 26 Branchbran 100% 8 / 8 Conditioncond 83.3% 5 / 6 MC/DCmcdc 66.6% 2 / 3 Subroutinesub 100% 5 / 5 Podpod n/a totaltotal 95.8% 46 / 48 CC 7 SCAR 15.7
CC
7
Cov
98%
__ANON__
7.0
BEGIN
1.0
BEGIN
1.0
CRAP 4.8
↑ Summary PrivateSetters.pm »
1 package MooseX::PrivateSetters::Role::Attribute;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 our $VERSION = '0.08';
7  
8 2 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 9 ▶before '_process_options' => sub {
Subroutine __ANON__: called CC=7 SCAR=19.5
11 9 my $class = shift;
12 9 my $name = shift;
13 9 my $options = shift;
14  
15 9 ▶ if ( exists $options->{is} &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $options->{"is"} and not exists $options->{"reader"} || exists $options->{"writer"}) 7 2 9
Condition83%5/6
exists $options->{"is"} and not exists $options->{"reader"} || exists $options->{"writer"}
!ll&&!rl&&r
027
exists $options->{'reader'} || exists $options->{'writer'}
l!l&&r!l&&!r
117
MC/DC66%2/3
exists $options->{"is"} and not exists $options->{"reader"} || exists $options->{"writer"}
exists $options->{"is"} exists $options->{'reader'} exists $options->{'writer'}
Truth table75%3/4
A and not(B || C)
A= exists $options->{"is"}B= exists $options->{'reader'}C= exists $options->{'writer'}
ABCresult
0XX0
11X0
1010
1001
16 ! ( exists $options->{reader} || exists $options->{writer} ) ) {
17 7 ▶ if ( $options->{is} eq 'ro' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($options->{'is'} eq 'ro') { } 1 6 7
elsif ($options->{'is'} eq 'rw') { } 5 1 6
18 1 $options->{reader} = $name;
19 1 delete $options->{is};
20 }
21 elsif ( $options->{is} eq 'rw' ) {
22 5 $options->{reader} = $name;
23 5 ▶ my $prefix = $name =~ /^_/ ? '_set' : '_set_';
Branch: 1 branch
BranchTrueFalseTotal
$name =~ /^_/ ? : 3 2 5
24 5 $options->{writer} = $prefix . $name;
25  
26 5 delete $options->{is};
27 }
28 }
29 2 };
30  
31 2 ▶no Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
32  
33 2 1;
34  
35 =head1 NAME
36  
37 MooseX::PrivateSetters::Role::Attribute - Names setters as such, and makes them private
38  
39 =head1 SYNOPSIS
40  
41 Moose::Exporter->setup_import_methods(
42 class_metaroles => {
43 attribute => ['MooseX::PrivateSetters::Role::Attribute'],
44 },
45 );
46  
47 =head1 DESCRIPTION
48  
49 This role applies a method modifier to the C<_process_options()>
50 method, and tweaks the writer parameters so that they are private with
51 an explicit '_set_attr' method. Getters are left unchanged. This role
52 copes with attributes intended to be private (ie, starts with an
53 underscore), with no double-underscore in the setter.
54  
55 For example:
56  
57 | Code | Reader | Writer |
58 |---------------------------+--------+-------------|
59 | has 'baz' => (is 'rw'); | baz() | _set_baz() |
60 | has 'baz' => (is 'ro'); | baz() | |
61 | has '_baz' => (is 'rw'); | _baz() | _set_baz() |
62 | has '__baz' => (is 'rw'); | _baz() | _set__baz() |
63  
64 You probably don't want to use this module. You probably should be
65 looking at L<MooseX::PrivateSetters> instead.
66  
67 =head1 AUTHOR
68  
69 brian greenfield C<< <briang@cpan.org> >>
70  
71 =head1 COPYRIGHT & LICENSE
72  
73 Copyright 2010 brian greenfield
74  
75 This program is free software; you can redistribute it and/or modify
76 it under the same terms as Perl itself.
↑ Summary PrivateSetters.pm »