MooseX::FollowPBP::Role::Attribute - MooseX::FollowPBP::Role::Attribute documentation


MooseX-FollowPBP documentation Contained in the MooseX-FollowPBP distribution.

Index


Code Index:

NAME

Top

MooseX::FollowPBP::Role::Attribute

VERSION

Top

version 0.05

SYNOPSIS

Top

  Moose::Util::MetaRole::apply_metaclass_roles(
      for             => $p{for_class},
      class_metaroles => {
          attribute => ['MooseX::FollowPBP::Role::Attribute'],
      },
  );

DESCRIPTION

Top

This role applies a method modifier to the _process_options() method, and tweaks the reader and writer parameters so that they follow the style recommended in Perl Best Practices.

AUTHOR

Top

Dave Rolsky <autarch@urth.org>

COPYRIGHT AND LICENSE

Top


MooseX-FollowPBP documentation Contained in the MooseX-FollowPBP distribution.

package MooseX::FollowPBP::Role::Attribute;
BEGIN {
  $MooseX::FollowPBP::Role::Attribute::VERSION = '0.05';
}

use strict;
use warnings;

use Moose::Role;

before _process_options => sub {
    my $class   = shift;
    my $name    = shift;
    my $options = shift;

    if (   exists $options->{is}
        && !( exists $options->{reader} || exists $options->{writer} )
        && $options->{is} ne 'bare' ) {
        my $get;
        my $set;

        if ( $name =~ s/^_// ) {
            $get = '_get_';
            $set = '_set_';
        }
        else {
            $get = 'get_';
            $set = 'set_';
        }

        $options->{reader} = $get . $name;

        if ( $options->{is} eq 'rw' ) {
            $options->{writer} = $set . $name;
        }

        delete $options->{is};
    }
};

no Moose::Role;

1;



__END__