sourCEntral - mobile manpages




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


version 0.25


  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;


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:


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.

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



Common numerical operations.


Common methods for string operations.


Methods for incrementing and decrementing a counter attribute.


Common methods for boolean values.


Common methods for hash references.


Common methods for inspecting hash references.


Common methods for array references.


Common list methods for array references.


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.


Bugs may be submitted through the RT bug tracker <> (or bug−MooseX−AttributeHelpers AT rt DOT cpan DOT org <mailto:bug-MooseX-AttributeHelpers AT rt DOT cpan DOT org>).

There is also a mailing list available for users of this distribution, at <>.

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


Stevan Little <stevan AT iinteractive DOT com>


Shawn M Moore <sartak AT gmail DOT com>

Stevan Little <stevan DOT little AT iinteractive DOT com>

Dave Rolsky <autarch AT urth DOT org>

Florian Ragwitz <rafl AT debian DOT org>

Yuval Kogman <nothingmuch AT woobling DOT org>

Jason May <jason DOT a DOT may AT gmail DOT com>

Karen Etheridge <ether AT cpan DOT org>

Cory G Watson <gphat AT onemogin DOT com>

Jesse Luehrs <doy AT tozt DOT net>

Robert Boone <robo4288 AT gmail DOT com>

Bruno Vecchi <vecchi DOT b AT gmail DOT com>

Johannes Plunien <plu AT pqpq DOT de>

Mike Whitaker <mike AT altrion DOT org>

Hans Dieter Pearcey <hdp AT weftsoar DOT net>

Paul Driver <frodwith AT gmail DOT com>

Robert ’phaylon’ Sedlacek <rs AT 474 DOT at>

Evan Carroll <me AT evancarroll DOT com>

Dagfinn Ilmari Mannsaaker <ilmari AT ilmari DOT org>

Chris Prather <cprather AT hdpublishing DOT com>

Tom Lanyon <tom AT netspot DOT com DOT au>

Chris Prather <chris AT prather DOT org>

nperez <nperez AT cpan DOT org>


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.