| 1 | package MooseX::Emulate::Class::Accessor::Fast; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 10 | ▶ | use Moose::Role; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 10 | ▶ | use Class::MOP (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 10 | ▶ | use Scalar::Util (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 10 | ▶ | use MooseX::Emulate::Class::Accessor::Fast::Meta::Accessor (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 10 | our $VERSION = '0.009032'; | |||||||||||||||||||||||||||
| 10 | 10 | $VERSION =~ tr/_//d; | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | =head1 NAME | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | MooseX::Emulate::Class::Accessor::Fast - Emulate Class::Accessor::Fast behavior using Moose attributes | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | =head1 SYNOPSYS | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | package MyClass; | ||||||||||||||||||||||||||||
| 19 | use Moose; | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | with 'MooseX::Emulate::Class::Accessor::Fast'; | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | #fields with readers and writers | ||||||||||||||||||||||||||||
| 25 | __PACKAGE__->mk_accessors(qw/field1 field2/); | ||||||||||||||||||||||||||||
| 26 | #fields with readers only | ||||||||||||||||||||||||||||
| 27 | __PACKAGE__->mk_ro_accessors(qw/field3 field4/); | ||||||||||||||||||||||||||||
| 28 | #fields with writers only | ||||||||||||||||||||||||||||
| 29 | __PACKAGE__->mk_wo_accessors(qw/field5 field6/); | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | This module attempts to emulate the behavior of L<Class::Accessor::Fast> as | ||||||||||||||||||||||||||||
| 35 | accurately as possible using the Moose attribute system. The public API of | ||||||||||||||||||||||||||||
| 36 | C<Class::Accessor::Fast> is wholly supported, but the private methods are not. | ||||||||||||||||||||||||||||
| 37 | If you are only using the public methods (as you should) migration should be a | ||||||||||||||||||||||||||||
| 38 | matter of switching your C<use base> line to a C<with> line. | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | While I have attempted to emulate the behavior of Class::Accessor::Fast as closely | ||||||||||||||||||||||||||||
| 41 | as possible bugs may still be lurking in edge-cases. | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | =head1 BEHAVIOR | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | Simple documentation is provided here for your convenience, but for more thorough | ||||||||||||||||||||||||||||
| 46 | documentation please see L<Class::Accessor::Fast> and L<Class::Accessor>. | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | =head2 A note about introspection | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | Please note that, at this time, the C<is> flag attribute is not being set. To | ||||||||||||||||||||||||||||
| 51 | determine the C<reader> and C<writer> methods using introspection in later versions | ||||||||||||||||||||||||||||
| 52 | of L<Class::MOP> ( > 0.38) please use the C<get_read_method> and C<get_write_method> | ||||||||||||||||||||||||||||
| 53 | methods in L<Class::MOP::Attribute>. Example | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | # with Class::MOP <= 0.38 | ||||||||||||||||||||||||||||
| 56 | my $attr = $self->meta->find_attribute_by_name($field_name); | ||||||||||||||||||||||||||||
| 57 | my $reader_method = $attr->reader || $attr->accessor; | ||||||||||||||||||||||||||||
| 58 | my $writer_method = $attr->writer || $attr->accessor; | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | # with Class::MOP > 0.38 | ||||||||||||||||||||||||||||
| 61 | my $attr = $self->meta->find_attribute_by_name($field_name); | ||||||||||||||||||||||||||||
| 62 | my $reader_method = $attr->get_read_method; | ||||||||||||||||||||||||||||
| 63 | my $writer_method = $attr->get_write_method; | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | =head1 METHODS | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | =head2 BUILD $self %args | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | Change the default Moose class building to emulate the behavior of C::A::F and | ||||||||||||||||||||||||||||
| 70 | store arguments in the instance hashref. | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | =cut | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 25 | ▶ | my $locate_metaclass = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.4
| |||||||||||||||||||||||||||||
| 75 | 25 | ▶ | my $class = Scalar::Util::blessed($_[0]) || $_[0]; | ||||||||||||||||||||||||||
|
Condition66%2/3
builtin::blessed($_[0]) || $_[0]
MC/DC0%0/2
builtin::blessed($_[0]) || $_[0]
builtin::blessed($_[0])
$_[0]
Truth table66%2/3
A || B
A= builtin::blessed($_[0])B= $_[0]
| |||||||||||||||||||||||||||||
| 76 | 25 | ▶ | return Class::MOP::get_metaclass_by_name($class) | ||||||||||||||||||||||||||
|
Condition66%2/3
Class::MOP::get_metaclass_by_name($class) || 'Moose::Meta::Class'->initialize($class)
MC/DC0%0/2
Class::MOP::get_metaclass_by_name($class) || 'Moose::Meta::Class'->initialize($class)
Class::MOP::get_metaclass_by_name($class)
'Moose::Meta::Class'->initialize($class)
Truth table66%2/3
A || B
A= Class::MOP::get_metaclass_by_name($class)B= 'Moose::Meta::Class'->initialize($class)
| |||||||||||||||||||||||||||||
| 77 | || Moose::Meta::Class->initialize($class); | ||||||||||||||||||||||||||||
| 78 | 10 | }; | |||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 18 | ▶ | sub BUILD { } | ||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 19 | ▶ | around 'BUILD' => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 83 | 19 | my $orig = shift; | |||||||||||||||||||||||||||
| 84 | 19 | my $self = shift; | |||||||||||||||||||||||||||
| 85 | 19 | my %args = %{ $_[0] }; | |||||||||||||||||||||||||||
| 86 | 19 | $self->$orig(\%args); | |||||||||||||||||||||||||||
| 87 | 19 | my @extra = grep { !exists($self->{$_}) } keys %args; | |||||||||||||||||||||||||||
| 88 | 19 | @{$self}{@extra} = @args{@extra}; | |||||||||||||||||||||||||||
| 89 | 19 | return $self; | |||||||||||||||||||||||||||
| 90 | 10 | }; | |||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | =head2 mk_accessors @field_names | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | Create read-write accessors. An attribute named C<$field_name> will be created. | ||||||||||||||||||||||||||||
| 95 | The name of the c<reader> and C<writer> methods will be determined by the return | ||||||||||||||||||||||||||||
| 96 | value of C<accessor_name_for> and C<mutator_name_for>, which by default return the | ||||||||||||||||||||||||||||
| 97 | name passed unchanged. If the accessor and mutator names are equal the C<accessor> | ||||||||||||||||||||||||||||
| 98 | attribute will be passes to Moose, otherwise the C<reader> and C<writer> attributes | ||||||||||||||||||||||||||||
| 99 | will be passed. Please see L<Class::MOP::Attribute> for more information. | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | =cut | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 10 | ▶ | sub mk_accessors { | ||||||||||||||||||||||||||
|
Subroutine
mk_accessors: called CC=12 SCAR=25.8
Pod
documented
| |||||||||||||||||||||||||||||
| 104 | 10 | my $self = shift; | |||||||||||||||||||||||||||
| 105 | 10 | my $meta = $locate_metaclass->($self); | |||||||||||||||||||||||||||
| 106 | 10 | my $class = $meta->name; | |||||||||||||||||||||||||||
| 107 | 10 | ▶ | confess("You are trying to modify ${class}, which has been made immutable, this is ". | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 108 | "not supported. Try subclassing ${class}, rather than monkeypatching it") | ||||||||||||||||||||||||||||
| 109 | if $meta->is_immutable; | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 10 | for my $attr_name (@_){ | |||||||||||||||||||||||||||
| 112 | 16 | ▶ | $meta->remove_attribute($attr_name) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 113 | if $meta->find_attribute_by_name($attr_name); | ||||||||||||||||||||||||||||
| 114 | 16 | my $reader = $self->accessor_name_for($attr_name); | |||||||||||||||||||||||||||
| 115 | 16 | my $writer = $self->mutator_name_for( $attr_name); | |||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | #dont overwrite existing methods | ||||||||||||||||||||||||||||
| 118 | 16 | ▶ | if($reader eq $writer){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 119 | 15 | ▶ | my %opts = ( $meta->has_method($reader) ? ( is => 'bare' ) : (accessor => $reader) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 120 | 15 | ▶ | my $attr = $meta->find_attribute_by_name($attr_name) || $meta->add_attribute($attr_name, %opts, | ||||||||||||||||||||||||||
|
Condition33%1/3
$meta->find_attribute_by_name($attr_name) || $meta->add_attribute($attr_name, %opts, 'traits', ['MooseX::Emulate::Class::Accessor::Fast::Meta::Role::Attribute'])
MC/DC0%0/2
$meta->find_attribute_by_name($attr_name) || $meta->add_attribute($attr_name, %opts, 'traits', ['MooseX::Emulate::Class::Accessor::Fast::Meta::Role::Attribute'])
$meta->find_attribute_by_name($attr_name)
$meta->add_attribute($attr_name, %opts, 'traits', ['MooseX::Emulate::Class::Accessor::Fast::Meta::Role::Attribute'])
Truth table33%1/3
A || B
A= $meta->find_attribute_by_name($attr_name)B= $meta->add_attribute($attr_name, %opts, 'traits', ['MooseX::Emulate::Class::Accessor::Fast::Meta::Role::Attribute'])
| |||||||||||||||||||||||||||||
| 121 | traits => ['MooseX::Emulate::Class::Accessor::Fast::Meta::Role::Attribute'] | ||||||||||||||||||||||||||||
| 122 | ); | ||||||||||||||||||||||||||||
| 123 | 15 | ▶ | if($attr_name eq $reader){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 124 | 15 | my $alias = "_${attr_name}_accessor"; | |||||||||||||||||||||||||||
| 125 | 15 | ▶ | next if $meta->has_method($alias); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 126 | 14 | $meta->add_method($alias => $attr->get_read_method_ref); | |||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||
| 128 | } else { | ||||||||||||||||||||||||||||
| 129 | 1 | ▶ | my @opts = ( $meta->has_method($writer) ? () : (writer => $writer) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 130 | 1 | ▶ | push(@opts, (reader => $reader)) unless $meta->has_method($reader); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 131 | 1 | ▶ | my $attr = $meta->find_attribute_by_name($attr_name) || $meta->add_attribute($attr_name, @opts, | ||||||||||||||||||||||||||
|
Condition33%1/3
$meta->find_attribute_by_name($attr_name) || $meta->add_attribute($attr_name, @opts, 'traits', ['MooseX::Emulate::Class::Accessor::Fast::Meta::Role::Attribute'])
MC/DC0%0/2
$meta->find_attribute_by_name($attr_name) || $meta->add_attribute($attr_name, @opts, 'traits', ['MooseX::Emulate::Class::Accessor::Fast::Meta::Role::Attribute'])
$meta->find_attribute_by_name($attr_name)
$meta->add_attribute($attr_name, @opts, 'traits', ['MooseX::Emulate::Class::Accessor::Fast::Meta::Role::Attribute'])
Truth table33%1/3
A || B
A= $meta->find_attribute_by_name($attr_name)B= $meta->add_attribute($attr_name, @opts, 'traits', ['MooseX::Emulate::Class::Accessor::Fast::Meta::Role::Attribute'])
| |||||||||||||||||||||||||||||
| 132 | traits => ['MooseX::Emulate::Class::Accessor::Fast::Meta::Role::Attribute'] | ||||||||||||||||||||||||||||
| 133 | ); | ||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | =head2 mk_ro_accessors @field_names | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | Create read-only accessors. | ||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | =cut | ||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | 4 | ▶ | sub mk_ro_accessors { | ||||||||||||||||||||||||||
|
Subroutine
mk_ro_accessors: called CC=9 SCAR=23.0
Pod
documented
| |||||||||||||||||||||||||||||
| 145 | 4 | my $self = shift; | |||||||||||||||||||||||||||
| 146 | 4 | my $meta = $locate_metaclass->($self); | |||||||||||||||||||||||||||
| 147 | 4 | my $class = $meta->name; | |||||||||||||||||||||||||||
| 148 | 4 | ▶ | confess("You are trying to modify ${class}, which has been made immutable, this is ". | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 149 | "not supported. Try subclassing ${class}, rather than monkeypatching it") | ||||||||||||||||||||||||||||
| 150 | if $meta->is_immutable; | ||||||||||||||||||||||||||||
| 151 | 4 | for my $attr_name (@_){ | |||||||||||||||||||||||||||
| 152 | 5 | ▶ | $meta->remove_attribute($attr_name) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 153 | if $meta->find_attribute_by_name($attr_name); | ||||||||||||||||||||||||||||
| 154 | 5 | my $reader = $self->accessor_name_for($attr_name); | |||||||||||||||||||||||||||
| 155 | 5 | ▶ | my @opts = ($meta->has_method($reader) ? (is => 'bare') : (reader => $reader) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 156 | 5 | ▶ | my $attr = $meta->add_attribute($attr_name, @opts, | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 157 | traits => ['MooseX::Emulate::Class::Accessor::Fast::Meta::Role::Attribute'] | ||||||||||||||||||||||||||||
| 158 | ) if scalar(@opts); | ||||||||||||||||||||||||||||
| 159 | 5 | ▶ | if($reader eq $attr_name && $reader eq $self->mutator_name_for($attr_name)){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$reader eq $attr_name and $reader eq $self->mutator_name_for($attr_name)
MC/DC0%0/2
$reader eq $attr_name and $reader eq $self->mutator_name_for($attr_name)
$reader eq $attr_name
$reader eq $self->mutator_name_for($attr_name)
Truth table33%1/3
A and B
A= $reader eq $attr_nameB= $reader eq $self->mutator_name_for($attr_name)
| |||||||||||||||||||||||||||||
| 160 | 5 | ▶ | $meta->add_method("_${attr_name}_accessor" => $attr->get_read_method_ref) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 161 | unless $meta->has_method("_${attr_name}_accessor"); | ||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | =head2 mk_ro_accessors @field_names | ||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | Create write-only accessors. | ||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | =cut | ||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | #this is retarded.. but we need it for compatibility or whatever. | ||||||||||||||||||||||||||||
| 173 | 4 | ▶ | sub mk_wo_accessors { | ||||||||||||||||||||||||||
|
Subroutine
mk_wo_accessors: called CC=9 SCAR=23.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 174 | 4 | my $self = shift; | |||||||||||||||||||||||||||
| 175 | 4 | my $meta = $locate_metaclass->($self); | |||||||||||||||||||||||||||
| 176 | 4 | my $class = $meta->name; | |||||||||||||||||||||||||||
| 177 | 4 | ▶ | confess("You are trying to modify ${class}, which has been made immutable, this is ". | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 178 | "not supported. Try subclassing ${class}, rather than monkeypatching it") | ||||||||||||||||||||||||||||
| 179 | if $meta->is_immutable; | ||||||||||||||||||||||||||||
| 180 | 4 | for my $attr_name (@_){ | |||||||||||||||||||||||||||
| 181 | 5 | ▶ | $meta->remove_attribute($attr_name) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 182 | if $meta->find_attribute_by_name($attr_name); | ||||||||||||||||||||||||||||
| 183 | 5 | my $writer = $self->mutator_name_for($attr_name); | |||||||||||||||||||||||||||
| 184 | 5 | ▶ | my @opts = ($meta->has_method($writer) ? () : (writer => $writer) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 185 | 5 | ▶ | my $attr = $meta->add_attribute($attr_name, @opts, | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 186 | traits => ['MooseX::Emulate::Class::Accessor::Fast::Meta::Role::Attribute'] | ||||||||||||||||||||||||||||
| 187 | ) if scalar(@opts); | ||||||||||||||||||||||||||||
| 188 | 5 | ▶ | if($writer eq $attr_name && $writer eq $self->accessor_name_for($attr_name)){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$writer eq $attr_name and $writer eq $self->accessor_name_for($attr_name)
MC/DC0%0/2
$writer eq $attr_name and $writer eq $self->accessor_name_for($attr_name)
$writer eq $attr_name
$writer eq $self->accessor_name_for($attr_name)
Truth table33%1/3
A and B
A= $writer eq $attr_nameB= $writer eq $self->accessor_name_for($attr_name)
| |||||||||||||||||||||||||||||
| 189 | 5 | ▶ | $meta->add_method("_${attr_name}_accessor" => $attr->get_write_method_ref) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 190 | unless $meta->has_method("_${attr_name}_accessor"); | ||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||
| 195 | =head2 follow_best_practices | ||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||
| 197 | Preface readers with 'get_' and writers with 'set_'. | ||||||||||||||||||||||||||||
| 198 | See original L<Class::Accessor> documentation for more information. | ||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||
| 200 | =cut | ||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||
| 202 | 1 | ▶ | sub follow_best_practice { | ||||||||||||||||||||||||||
|
Subroutine
follow_best_practice: called CC=1 SCAR=0.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 203 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 204 | 1 | my $meta = $locate_metaclass->($self); | |||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||
| 206 | 1 | $meta->remove_method('mutator_name_for'); | |||||||||||||||||||||||||||
| 207 | 1 | $meta->remove_method('accessor_name_for'); | |||||||||||||||||||||||||||
| 208 | 0 | ▶ | $meta->add_method('mutator_name_for', sub{ return "set_".$_[1] }); | ||||||||||||||||||||||||||
|
Subroutine
mutator_name_for: called CC=1 SCAR=0.4
Subroutine
__ANON__: not called CC=1 SCAR=0.4
| |||||||||||||||||||||||||||||
| 209 | 0 | ▶ | $meta->add_method('accessor_name_for', sub{ return "get_".$_[1] }); | ||||||||||||||||||||||||||
|
Subroutine
accessor_name_for: called CC=1 SCAR=0.4
Subroutine
__ANON__: not called CC=1 SCAR=0.4
| |||||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||
| 212 | =head2 mutator_name_for | ||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||
| 214 | =head2 accessor_name_for | ||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||
| 216 | See original L<Class::Accessor> documentation for more information. | ||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||
| 218 | =cut | ||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||
| 220 | 25 | ▶ | sub mutator_name_for { return $_[1] } | ||||||||||||||||||||||||||
|
Subroutine
mutator_name_for: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 221 | 25 | ▶ | sub accessor_name_for { return $_[1] } | ||||||||||||||||||||||||||
|
Subroutine
accessor_name_for: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||
| 223 | =head2 set | ||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||
| 225 | See original L<Class::Accessor> documentation for more information. | ||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||
| 227 | =cut | ||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||
| 229 | 1 | ▶ | sub set { | ||||||||||||||||||||||||||
|
Subroutine
set: called CC=4 SCAR=14.3
Pod
documented
| |||||||||||||||||||||||||||||
| 230 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 231 | 1 | my $k = shift; | |||||||||||||||||||||||||||
| 232 | 1 | ▶ | confess "Wrong number of arguments received" unless scalar @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 233 | 1 | my $meta = $locate_metaclass->($self); | |||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||
| 235 | 1 | ▶ | confess "No such attribute '$k'" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 236 | unless ( my $attr = $meta->find_attribute_by_name($k) ); | ||||||||||||||||||||||||||||
| 237 | 1 | my $writer = $attr->get_write_method; | |||||||||||||||||||||||||||
| 238 | 1 | ▶ | $self->$writer(@_ > 1 ? [@_] : @_); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||
| 241 | =head2 get | ||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||
| 243 | See original L<Class::Accessor> documentation for more information. | ||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||
| 245 | =cut | ||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||
| 247 | 2 | ▶ | sub get { | ||||||||||||||||||||||||||
|
Subroutine
get: called CC=5 SCAR=17.0
Pod
documented
| |||||||||||||||||||||||||||||
| 248 | 2 | my $self = shift; | |||||||||||||||||||||||||||
| 249 | 2 | ▶ | confess "Wrong number of arguments received" unless scalar @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 250 | 2 | my $meta = $locate_metaclass->($self); | |||||||||||||||||||||||||||
| 251 | 2 | my @values; | |||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||
| 253 | 2 | for( @_ ){ | |||||||||||||||||||||||||||
| 254 | 2 | ▶ | confess "No such attribute '$_'" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 255 | unless ( my $attr = $meta->find_attribute_by_name($_) ); | ||||||||||||||||||||||||||||
| 256 | 2 | my $reader = $attr->get_read_method; | |||||||||||||||||||||||||||
| 257 | 2 | ▶ | @_ > 1 ? push(@values, $self->$reader) : return $self->$reader; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||
| 260 | 0 | return @values; | |||||||||||||||||||||||||||
| 261 | } | ||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||
| 263 | 1 | ▶ | sub make_accessor { | ||||||||||||||||||||||||||
|
Subroutine
make_accessor: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 264 | 1 | my($class, $field) = @_; | |||||||||||||||||||||||||||
| 265 | 1 | my $meta = $locate_metaclass->($class); | |||||||||||||||||||||||||||
| 266 | 1 | ▶ | my $attr = $meta->find_attribute_by_name($field) || $meta->add_attribute($field, | ||||||||||||||||||||||||||
|
Condition33%1/3
$meta->find_attribute_by_name($field) || $meta->add_attribute($field, 'traits', ['MooseX::Emulate::Class::Accessor::Fast::Meta::Role::Attribute'], 'is', 'bare')
MC/DC0%0/2
$meta->find_attribute_by_name($field) || $meta->add_attribute($field, 'traits', ['MooseX::Emulate::Class::Accessor::Fast::Meta::Role::Attribute'], 'is', 'bare')
$meta->find_attribute_by_name($field)
$meta->add_attribute($field, 'traits', ['MooseX::Emulate::Class::Accessor::Fast::Meta::Role::Attribute'], 'is', 'bare')
Truth table33%1/3
A || B
A= $meta->find_attribute_by_name($field)B= $meta->add_attribute($field, 'traits', ['MooseX::Emulate::Class::Accessor::Fast::Meta::Role::Attribute'], 'is', 'bare')
| |||||||||||||||||||||||||||||
| 267 | traits => ['MooseX::Emulate::Class::Accessor::Fast::Meta::Role::Attribute'], | ||||||||||||||||||||||||||||
| 268 | is => 'bare', | ||||||||||||||||||||||||||||
| 269 | ); | ||||||||||||||||||||||||||||
| 270 | 1 | my $reader = $attr->get_read_method_ref; | |||||||||||||||||||||||||||
| 271 | 1 | my $writer = $attr->get_write_method_ref; | |||||||||||||||||||||||||||
| 272 | 3 | ▶ | return sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.1
| |||||||||||||||||||||||||||||
| 273 | 3 | my $self = shift; | |||||||||||||||||||||||||||
| 274 | 3 | ▶ | return $reader->($self) unless @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 275 | 1 | ▶ | return $writer->($self,(@_ > 1 ? [@_] : @_)); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||
| 277 | 1 | } | |||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||
| 280 | 1 | ▶ | sub make_ro_accessor { | ||||||||||||||||||||||||||
|
Subroutine
make_ro_accessor: called CC=2 SCAR=7.4
Pod
undocumented
| |||||||||||||||||||||||||||||
| 281 | 1 | my($class, $field) = @_; | |||||||||||||||||||||||||||
| 282 | 1 | my $meta = $locate_metaclass->($class); | |||||||||||||||||||||||||||
| 283 | 1 | ▶ | my $attr = $meta->find_attribute_by_name($field) || $meta->add_attribute($field, | ||||||||||||||||||||||||||
|
Condition33%1/3
$meta->find_attribute_by_name($field) || $meta->add_attribute($field, 'traits', ['MooseX::Emulate::Class::Accessor::Fast::Meta::Role::Attribute'], 'is', 'bare')
MC/DC0%0/2
$meta->find_attribute_by_name($field) || $meta->add_attribute($field, 'traits', ['MooseX::Emulate::Class::Accessor::Fast::Meta::Role::Attribute'], 'is', 'bare')
$meta->find_attribute_by_name($field)
$meta->add_attribute($field, 'traits', ['MooseX::Emulate::Class::Accessor::Fast::Meta::Role::Attribute'], 'is', 'bare')
Truth table33%1/3
A || B
A= $meta->find_attribute_by_name($field)B= $meta->add_attribute($field, 'traits', ['MooseX::Emulate::Class::Accessor::Fast::Meta::Role::Attribute'], 'is', 'bare')
| |||||||||||||||||||||||||||||
| 284 | traits => ['MooseX::Emulate::Class::Accessor::Fast::Meta::Role::Attribute'], | ||||||||||||||||||||||||||||
| 285 | is => 'bare', | ||||||||||||||||||||||||||||
| 286 | ); | ||||||||||||||||||||||||||||
| 287 | 1 | return $attr->get_read_method_ref; | |||||||||||||||||||||||||||
| 288 | } | ||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||
| 291 | 1 | ▶ | sub make_wo_accessor { | ||||||||||||||||||||||||||
|
Subroutine
make_wo_accessor: called CC=2 SCAR=7.4
Pod
undocumented
| |||||||||||||||||||||||||||||
| 292 | 1 | my($class, $field) = @_; | |||||||||||||||||||||||||||
| 293 | 1 | my $meta = $locate_metaclass->($class); | |||||||||||||||||||||||||||
| 294 | 1 | ▶ | my $attr = $meta->find_attribute_by_name($field) || $meta->add_attribute($field, | ||||||||||||||||||||||||||
|
Condition33%1/3
$meta->find_attribute_by_name($field) || $meta->add_attribute($field, 'traits', ['MooseX::Emulate::Class::Accessor::Fast::Meta::Role::Attribute'], 'is', 'bare')
MC/DC0%0/2
$meta->find_attribute_by_name($field) || $meta->add_attribute($field, 'traits', ['MooseX::Emulate::Class::Accessor::Fast::Meta::Role::Attribute'], 'is', 'bare')
$meta->find_attribute_by_name($field)
$meta->add_attribute($field, 'traits', ['MooseX::Emulate::Class::Accessor::Fast::Meta::Role::Attribute'], 'is', 'bare')
Truth table33%1/3
A || B
A= $meta->find_attribute_by_name($field)B= $meta->add_attribute($field, 'traits', ['MooseX::Emulate::Class::Accessor::Fast::Meta::Role::Attribute'], 'is', 'bare')
| |||||||||||||||||||||||||||||
| 295 | traits => ['MooseX::Emulate::Class::Accessor::Fast::Meta::Role::Attribute'], | ||||||||||||||||||||||||||||
| 296 | is => 'bare', | ||||||||||||||||||||||||||||
| 297 | ); | ||||||||||||||||||||||||||||
| 298 | 1 | return $attr->get_write_method_ref; | |||||||||||||||||||||||||||
| 299 | } | ||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||
| 301 | 10 | 1; | |||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||
| 303 | =head2 meta | ||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||
| 305 | See L<Moose::Meta::Class>. | ||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||
| 307 | =cut | ||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||
| 309 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||
| 311 | L<Moose>, L<Moose::Meta::Attribute>, L<Class::Accessor>, L<Class::Accessor::Fast>, | ||||||||||||||||||||||||||||
| 312 | L<Class::MOP::Attribute>, L<MooseX::Adopt::Class::Accessor::Fast> | ||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||
| 314 | =head1 AUTHORS | ||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||
| 316 | Guillermo Roditi (groditi) <groditi@cpan.org> | ||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||
| 318 | With contributions from: | ||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||
| 320 | =over 4 | ||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||
| 322 | =item Tomas Doran (t0m) <bobtfish@bobtfish.net> | ||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||
| 324 | =item Florian Ragwitz (rafl) <rafl@debian.org> | ||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||
| 326 | =back | ||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||
| 328 | =head1 LICENSE | ||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||
| 330 | You may distribute this code under the same terms as Perl itself. | ||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||
| 332 | =cut | ||||||||||||||||||||||||||||