NAME

MooX::Attributes::Shadow::Role - enumerate shadowable attributes in a contained class

SYNOPSIS

# in the contained class
package Foo;
use Moo;
with 'MooX::Attributes::Shadow::Role';

shadowable_attrs 'x', 'y';

has x => ( is => 'ro' );
has y => ( is => 'ro' );


# in the container class

package Bar;

use Moo;
use Foo;

# create accessors with a prefix to avoid collisions; no need to
# specify which ones
Foo->shadow_attrs( fmt => sub { 'pfx_' . shift } );

# later in the code, use the attributes when creating a new Foo
# object.

sub create_foo {
  my $self = shift;
  my $foo = Foo->new( Foo->xtract_attrs( $self ) );
}

DESCRIPTION

MooX::Attributes::Shadow::Role provides a means for a class to identify attributes which should be shadowed to classes which contain it. (See MooX::Attributes::Shadow for more on what this means). A class containing a class composed with this role need know nothing about the attributes which will be shadowed, and can use the class methods to integrate the shadowable attributes into their interface.

INTERFACE

Contained class functions

shadowable_attrs
shadowable_attrs @attrs;

This is called by the contained class to identify which attributes are available for shadowing. It does not create them, it merely records them.

Class methods for use by the Container Classes

shadow_attrs
ContainedClass->shadow_attrs( %options );

This method creates attributes shadowing the ContainedClass's shadowable attributes in the class which calls it. The attributes are created as read-only. There is no means of specifying additional attribute options.

It takes the following options:

fmt

This is a reference to a subroutine which should return a modified attribute name (e.g. to prevent attribute collisions). It is passed the attribute name as its first parameters.

attrs

This is a list of attributes to shadow; this overrides the list provided by the contained class in the call to shadowable_attrs.

xtract_attrs
%shadowed_attrs = ContainedClass->xtract_attrs( $obj );

This is extracts the shadowed attributes from an object instantiated from the containing class.

COPYRIGHT & LICENSE

Copyright 2012 Smithsonian Astrophysical Observatory

This software is released under the GNU General Public License. You may find a copy at

http://www.fsf.org/copyleft/gpl.html

AUTHOR

Diab Jerius <djerius@cfa.harvard.edu>