Reference

MooseX::AttributeHelpers(3pm)

(DEPRECATED) Extend your attribute interfaces

NAME

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

VERSION

version 0.25

SYNOPSIS

  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

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

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

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.

DEPRECATION NOTICE

The functionality in this family of modules is now implemented in the Moose core as Moose::Meta::Attribute::Native. No more development is being done on MooseX::AttributeHelpers, so we encourage you to switch to native attribute traits.

SUPPORT

Bugs may be submitted through the RT bug tracker <https://rt.cpan.org/Public/Dist/Display.html?Name=MooseX-AttributeHelpers> (or [email protected] <mailto:[email protected]>).

There is also a mailing list available for users of this distribution, at <http://lists.perl.org/list/moose.html>.

There is also an irc channel available for users of this distribution, at "#moose" on "irc.perl.org" <irc://irc.perl.org/#moose>.

AUTHOR

Stevan Little <[email protected]>

CONTRIBUTORS

•

Shawn M Moore <[email protected]>

•

Stevan Little <[email protected]>

•

Dave Rolsky <[email protected]>

•

Florian Ragwitz <[email protected]>

•

Yuval Kogman <[email protected]>

•

Jason May <[email protected]>

•

Karen Etheridge <[email protected]>

•

Cory G Watson <[email protected]>

•

Jesse Luehrs <[email protected]>

•

Robert Boone <[email protected]>

•

Bruno Vecchi <[email protected]>

•

Johannes Plunien <[email protected]>

•

Mike Whitaker <[email protected]>

•

Hans Dieter Pearcey <[email protected]>

•

Paul Driver <[email protected]>

•

Robert 'phaylon' Sedlacek <[email protected]>

•

Evan Carroll <[email protected]>

•

Dagfinn Ilmari Mannsaaker <[email protected]>

•

Chris Prather <[email protected]>

•

Tom Lanyon <[email protected]>

•

Chris Prather <[email protected]>

•

nperez <[email protected]>

COPYRIGHT AND LICENSE

This software is copyright (c) 2007 by Stevan Little and Infinity Interactive, Inc.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

History