The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

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 (or bug-MooseX-AttributeHelpers@rt.cpan.org).

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.

AUTHOR

Stevan Little <stevan@iinteractive.com>

CONTRIBUTORS

  • Shawn M Moore <sartak@gmail.com>

  • Stevan Little <stevan.little@iinteractive.com>

  • Dave Rolsky <autarch@urth.org>

  • Florian Ragwitz <rafl@debian.org>

  • Yuval Kogman <nothingmuch@woobling.org>

  • Jason May <jason.a.may@gmail.com>

  • Karen Etheridge <ether@cpan.org>

  • Cory G Watson <gphat@onemogin.com>

  • Jesse Luehrs <doy@tozt.net>

  • Robert Boone <robo4288@gmail.com>

  • Bruno Vecchi <vecchi.b@gmail.com>

  • Johannes Plunien <plu@pqpq.de>

  • Mike Whitaker <mike@altrion.org>

  • Hans Dieter Pearcey <hdp@weftsoar.net>

  • Paul Driver <frodwith@gmail.com>

  • Robert 'phaylon' Sedlacek <rs@474.at>

  • Evan Carroll <me@evancarroll.com>

  • Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>

  • Chris Prather <cprather@hdpublishing.com>

  • Tom Lanyon <tom@netspot.com.au>

  • Chris Prather <chris@prather.org>

  • nperez <nperez@cpan.org>

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.