Fey::Role::MakesAliasObjects - A role for objects with separate alias objects


Fey documentation Contained in the Fey distribution.

Index


Code Index:

NAME

Top

Fey::Role::MakesAliasObjects - A role for objects with separate alias objects

VERSION

Top

version 0.40

SYNOPSIS

Top

  package My::Thing;

  use Moose;

  with 'Fey::Role::MakesAliasObjects'
      => { alias_class => 'My::Alias',
           self_param  => 'thing',
           name_param  => 'alias_name',
         };

DESCRIPTION

Top

This role adds a "make an alias object" method to a class. This is for things like tables and columns, which can have aliases.

PARAMETERS

Top

alias_class

The name of the class whose new() is called by the alias() method (see below). Required.

self_param

The name of the parameter to pass $self to the alias_class' new() method as. Required.

name_param

The name of the parameter to alias() that passing a single string is assumed to be. Defaults to alias_name.

METHODS

Top

$obj->alias()

  my $alias = $obj->alias(alias_name => 'an_alias', %other_params);

  my $alias = $obj->alias('an_alias');

Create a new alias for this object. If a single parameter is provided, it is assumed to be whatever the name_param parameter specifies (see above).

BUGS

Top

See Fey for details on how to report bugs.

AUTHOR

Top

Dave Rolsky <autarch@urth.org>

COPYRIGHT AND LICENSE

Top


Fey documentation Contained in the Fey distribution.

package Fey::Role::MakesAliasObjects;
BEGIN {
  $Fey::Role::MakesAliasObjects::VERSION = '0.40';
}

use strict;
use warnings;
use namespace::autoclean;

use Fey::Types qw( ClassName Str );

use MooseX::Role::Parameterized;

parameter 'alias_class' => (
    is       => 'ro',
    isa      => ClassName,
    required => 1,
);

parameter 'self_param' => (
    is       => 'ro',
    isa      => Str,
    required => 1,
);

parameter 'name_param' => (
    is      => 'ro',
    isa     => Str,
    default => 'alias_name',
);

role {
    my $p = shift;

    my $alias_class = $p->alias_class();
    my $self_param  = $p->self_param();
    my $name_param  = $p->name_param();

    method 'alias' => sub {
        my $self = shift;
        my %p = @_ == 1 ? ( $name_param => $_[0] ) : @_;

        return $alias_class->new( $self_param => $self, %p );
    };
};

1;

# ABSTRACT: A role for objects with separate alias objects




__END__