MooX::Emulate::Class::Accessor::Fast - Emulate Class::Accessor::Fast behavior using Moo attributes.
package MyClass; use Moo; with 'MooX::Emulate::Class::Accessor::Fast'; # Fields with readers and writers: __PACKAGE__->mk_accessors(qw/field1 field2/); # Fields with readers only: __PACKAGE__->mk_ro_accessors(qw/field3 field4/); # Fields with writers only: __PACKAGE__->mk_wo_accessors(qw/field5 field6/);
This module attempts to emulate the behavior of Class::Accessor::Fast as accurately as possible using the Moo attribute system. The public API of Class::Accessor::Fast is wholly supported, but the private methods are not. If you are only using the public methods (as you should) migration should be a matter of switching your use base line to a with line.
use base
with
This module is a straight fork-and-port of MooseX::Emulate::Class::Accessor::Fast version 0.00903 for Moo. All tests from the original Moose module pass or were, as little as possible, modified to pass. Much of the documentation, code concepts, and tests are just straight copied from the original module. The core functionality, though, had to be a complete rewrite for Moo.
0.00903
While we have attempted to emulate the behavior of Class::Accessor::Fast as closely as possible bugs may still be lurking in edge-cases.
Simple documentation is provided here for your convenience, but for more thorough documentation please see Class::Accessor::Fast and Class::Accessor.
__PACKAGE__->mk_accessors( @field_names );
See "mk_accessors" in Class::Accessor.
__PACKAGE__->mk_ro_accessors( @field_names );
See "mk_ro_accessors" in Class::Accessor.
__PACKAGE__->mk_wo_accessors( @field_names );
See "mk_wo_accessors" in Class::Accessor.
__PACKAGE__->follow_best_practice();
See "follow_best_practice" in Class::Accessor.
sub mutator_name_for { 'change_' . $_[1] }
See "MAKING ACCESSORS" in Class::Accessor.
sub accessor_name_for { 'retrieve_' . $_[1] }
$object->set( $field => $value );
See "set" in Class::Accessor.
my $value = $object->get( $field ); my @values = $object->get( $field1, $field2 );
See "get" in Class::Accessor.
my $coderef = $class->make_accessor( $field );
See "make_accessor" in Class::Accessor.
my $coderef = $class->make_ro_accessor( $field );
See "make_ro_accessor" in Class::Accessor.
my $coderef = $class->make_wo_accessor( $field );
See "make_wo_accessor" in Class::Accessor.
Moo, Class::Accessor, Class::Accessor::Fast, MooseX::Emulate::Class::Accessor::Fast
Aran Clary Deltac <bluefeet@gmail.com>
Original code, tests, and documentation taken from MooseX::Emulate::Class::Accessor::Fast. Thanks!
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install MooX::Emulate::Class::Accessor::Fast, copy and paste the appropriate command in to your terminal.
cpanm
cpanm MooX::Emulate::Class::Accessor::Fast
CPAN shell
perl -MCPAN -e shell install MooX::Emulate::Class::Accessor::Fast
For more information on module installation, please visit the detailed CPAN module installation guide.