MooseX::AttributeHelpers - Extend your attribute interfaces (deprecated)


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

Index


Code Index:

NAME

Top

MooseX::AttributeHelpers - Extend your attribute interfaces (deprecated)

SYNOPSIS

Top

  package MyClass;
  use Moose;
  use MooseX::AttributeHelpers;

  has 'mapping' => (
      metaclass => 'Collection::Hash',
      is        => 'rw',
      isa       => 'HashRef[Str]',
      default   => sub { {} },
      provides  => {
          exists    => 'exists_in_mapping',
          keys      => 'ids_in_mapping',
          get       => 'get_mapping',
          set       => 'set_mapping',
      },
      curries  => {
          set       => { set_quantity => [ 'quantity' ] }
      }
  );




  # ...

  my $obj = MyClass->new;
  $obj->set_quantity(10);      # quantity => 10
  $obj->set_mapping(4, 'foo'); # 4 => 'foo'
  $obj->set_mapping(5, 'bar'); # 5 => 'bar'
  $obj->set_mapping(6, 'baz'); # 6 => 'baz'




  # prints 'bar'
  print $obj->get_mapping(5) if $obj->exists_in_mapping(5);

  # prints '4, 5, 6'
  print join ', ', $obj->ids_in_mapping;

DESCRIPTION

Top

This distribution is deprecated. The features it provides have been added to the Moose core code as Moose::Meta::Attribute::Native. This distribution should not be used by any new code.

While Moose attributes provide you with a way to name your accessors, readers, writers, clearers and predicates, this library provides commonly used attribute helper methods for more specific types of data.

As seen in the SYNOPSIS, you specify the extension via the metaclass parameter. Available meta classes are:

PARAMETERS

Top

provides

This points to a hashref that uses provider for the keys and method for the values. The method will be added to the object itself and do what you want.

curries

This points to a hashref that uses provider for the keys and has two choices for the value:

You can supply {method => [ @args ]} for the values. The method will be added to the object itself (always using @args as the beginning arguments).

Another approach to curry a method provider is to supply a coderef instead of an arrayref. The code ref takes $self, $body, and any additional arguments passed to the final method.

  # ...

  curries => {
      grep => {
          times_with_day => sub {
              my ($self, $body, $datetime) = @_;
              $body->($self, sub { $_->ymd eq $datetime->ymd });
          }
      }
  }

  # ...

  $obj->times_with_day(DateTime->now); # takes datetime argument, checks day




METHOD PROVIDERS

Top

Number

Common numerical operations.

String

Common methods for string operations.

Counter

Methods for incrementing and decrementing a counter attribute.

Bool

Common methods for boolean values.

Collection::Hash

Common methods for hash references.

Collection::ImmutableHash

Common methods for inspecting hash references.

Collection::Array

Common methods for array references.

Collection::List

Common list methods for array references.

CAVEAT

Top

This is an early release of this module. Right now it is in great need of documentation and tests in the test suite. However, we have used this module to great success at $work where it has been tested very thoroughly and deployed into a major production site.

I plan on getting better docs and tests in the next few releases, but until then please refer to the few tests we do have and feel free email and/or message me on irc.perl.org if you have any questions.

TODO

Top

We need tests and docs badly.

BUGS

Top

All complex software has bugs lurking in it, and this module is no exception. If you find a bug please either email me, or add the bug to cpan-RT.

AUTHOR

Top

Stevan Little <stevan@iinteractive.com>

with contributions from:

Robert (rlb3) Boone

Paul (frodwith) Driver

Shawn (Sartak) Moore

Chris (perigrin) Prather

Robert (phaylon) Sedlacek

Tom (dec) Lanyon

Yuval Kogman

Jason May

Cory (gphat) Watson

Florian (rafl) Ragwitz

Evan Carroll

Jesse (doy) Luehrs

COPYRIGHT AND LICENSE

Top


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

package MooseX::AttributeHelpers;

our $VERSION   = '0.23';
$VERSION = eval $VERSION;
our $AUTHORITY = 'cpan:STEVAN';

use Moose 0.56 ();

use MooseX::AttributeHelpers::Meta::Method::Provided;
use MooseX::AttributeHelpers::Meta::Method::Curried;

use MooseX::AttributeHelpers::Trait::Bool;
use MooseX::AttributeHelpers::Trait::Counter;
use MooseX::AttributeHelpers::Trait::Number;
use MooseX::AttributeHelpers::Trait::String;
use MooseX::AttributeHelpers::Trait::Collection::List;
use MooseX::AttributeHelpers::Trait::Collection::Array;
use MooseX::AttributeHelpers::Trait::Collection::Hash;
use MooseX::AttributeHelpers::Trait::Collection::ImmutableHash;
use MooseX::AttributeHelpers::Trait::Collection::Bag;

use MooseX::AttributeHelpers::Counter;
use MooseX::AttributeHelpers::Number;
use MooseX::AttributeHelpers::String;
use MooseX::AttributeHelpers::Bool;
use MooseX::AttributeHelpers::Collection::List;
use MooseX::AttributeHelpers::Collection::Array;
use MooseX::AttributeHelpers::Collection::Hash;
use MooseX::AttributeHelpers::Collection::ImmutableHash;
use MooseX::AttributeHelpers::Collection::Bag;

1;

__END__