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

NAME

Data::MultiValued::AttributeTrait - "base role" for traits of multi-valued Moose attributes

VERSION

version 0.0.1_4

DESCRIPTION

Don't use this role directly, use Data::MultiValued::AttributeTrait::Tags, Data::MultiValued::AttributeTrait::Ranges or Data::MultiValued::AttributeTrait::TagsAndRanges.

This role (together with Data::MultiValued::AttributeAccessors) defines all the basic plumbing to glue Data::MultiValued::Tags etc into Moose attributes.

Implementation details

The multi-value object is stored in the instance slot named by the "full_storage_slot" attribute attribute. before modifiers on getters load the appropriate value from the multi-value object into the regular instance slot, after modifiers on setters store the value from the regular instance slot into the multi-value object.

Attributes

This trait adds some attributes to the attribute declarations in your class. Example:

  has stuff => (
    is => 'rw',
    isa => 'Int',
    traits => ['MultiValued::Tags'],
    predicate => 'has_stuff',
    multi_accessor => 'stuff_tagged',
    multi_predicate => 'has_stuff_tagged',
  );

ATTRIBUTES

full_storage_slot

The instance slot to use to store the Data::MultiValued::Tags or similar object. Defaults to "${name}__MULTIVALUED_STORAGE__", where $name is the attribute name.

multi_accessor

multi_reader

multi_writer

multi_predicate

multi_clearer

The names to use for the various additional accessors. See Class::MOP::Attribute for details. These default to "${name}_multi" where $name is the name of the corresponding non-multi accessor. So, for example,

  has stuff => (
    is => 'rw',
    traits => ['MultiValued::Tags'],
  );

will create a stuff read / write accessor and a stuff_multi read / write tagged accessor.

METHODS

slots

Adds the "full_storage_slot" to the list of used slots.

set_full_storage

Stores a new instance of "multivalue_storage_class" into the "full_storage_slot" of the instance.

get_full_storage

Retrieves the value of the "full_storage_slot" of the instance.

full_storage

Returns an instance of "multivalue_storage_class", either by retrieving it from the instance, or by creating one (and setting it in the instance). Calls "get_full_storage" and "set_full_storage".

accessor_metaclass

Makes sure that all accessors for this attribute are created via the Data::MultiValued::AttributeAccessors method meta class.

install_accessors

After the regular Moose::Meta::Attribute method, installs the multi-value accessors.

Each installed normal accessor gets a multi-value version

You can add or rename the multi-value version by using the attributes described above

If you are passing explicit subrefs for your accessors, things won't work.

load_multi_value

Retrieves a value from the multi-value object, and stores it in the regular slot in the instance. If the value is not found, clears the slot.

This traps the Data::MultiValued::Exceptions::NotFound exception that may be thrown by the multi-value object, but re-throws any other exception.

raw_clear_value

Clears the instance slot. Does the same as "clear_value" in Moose::Meta::Attribute, but we need this method because the other one gets changed by this trait.

store_multi_value

Gets the value from the regular slot in the instance, and stores it into the multi-value object.

get_value

Before the normal method, calls "load_multi_value". Normally, no options will be passed to the multi-value object get method.

get_multi_value

Sets the options that "load_multi_value" will use, then calls "get_value".

The options are passed via an ugly localised package variable. There might be a better way.

set_initial_value

After the normal method, calls "store_multi_value".

set_value

set_multi_value

Just like "get_value" and "get_multi_value", but calling "store_multi_value" after the regular set_value

has_value

has_multi_value

Just like "get_value" and "get_multi_value".

clear_value

clear_multi_value

Call the clear method on the multi-value object.

get_multi_read_method

get_multi_write_method

Return the name of the reader or writer method, honoring "multi_reader", "multi_writer" and "multi_accessor".

REQUIREMENTS

These methods must be provided by any class consuming this role. See Data::MultiValued::AttributeTrait::Tags etc. for examples.

multivalue_storage_class

The class to use to create the multi-value objects.

opts_to_pass_set

Which options to pass from the multi-value accessors to the set method of the multi-value object.

opts_to_pass_get

Which options to pass from the multi-value accessors to the get method of the multi-value object.

Serialisation helpers

These are used through Data::MultiValued::UglySerializationHelperRole.

_rebless_slot

Blesses the value inside the "full_storage_slot" of the instance into "multivalue_storage_class", then calls _rebless_storage on it.

_as_hash

Returns the result of calling _as_hash on the value inside the "full_storage_slot" of the instance. Returns nothing if the slot does not have a value.

AUTHOR

Gianni Ceccarelli <dakkar@thenautilus.net>

COPYRIGHT AND LICENSE

This software is copyright (c) 2011 by Net-a-Porter.com.

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