Newcomen

Description A static content generator.
Newcomen > Perl Modules > Newcomen::Role::Attribute::Component
Source

Index


NAME ^

Newcomen::Role::Attribute::Component - Moose role (parameterized) for components.

SYNOPSIS ^

The consuming role for a specific component (Foo):

package Newcomen::Role::Attribute::Foo;

use namespace::autoclean;
use Moose::Role;

with 'Newcomen::Role::Attribute::Component' => { 'component' => 'Foo' };

1;

In the consuming class:

with 'Newcomen::Role::Attribute::Core';
with 'Newcomen::Role::Attribute::Foo';

# Then _foo() is available:
my $foo = $self -> _foo ();

DESCRIPTION ^

This parameterized Moose role may be used to create other roles that provide an attribute to the consuming classes to easily access a specific Newcomen component. All components provided by the core (see Newcomen::Core) are supported.

OPTIONS ^

In the consuming role, the component has to be specified:

with 'Newcomen::Role::Attribute::Component' => { 'component' => 'Foo' };

This example would create the attribute _foo, that can be used as a getter by consuming classes to access the Foo component. The core has to provide a foo() method in that case. Both the attribute name and the core's method name will be derived from the supplied component parameter by converting it to lowercase. The type of the attribute must match the component name prefixed with 'Newcomen::', in the example this would be Newcomen::Foo.

It is required that the consuming class provides a _core() method that returns the Newcomen::Core instance. Consuming the role Newcomen::Role::Attribute::Core is the easiest way to satisfy this requirement. The _foo() method is only a shortcut to $instance->_core()->foo():

# In the consuming class:

with 'Newcomen::Role::Attribute::Core';
with 'Newcomen::Role::Attribute::Foo';

# Using Newcomen::Role::Attribute::Foo's attribute:
my $foo = $self -> _foo ();

# Same value, using only the core attribute:
my $foo = $self -> _core () -> foo ();

A builder for the attribute will also be created. In the example the builder would be a method named _build_foo() (the all lowercase component parameter, prefixed by '_build_'). The consuming class must not use this name for one of its own methods. The builder is called on first access to the attribute (i.e. the attribute is set to be lazy).

SEE ALSO ^

Moose, Newcomen::Core, Newcomen::Role::Attribute::Core

VERSION ^

This is version 2014052501.

AUTHOR ^

Stefan Goebel - newcomen {at} subtype {dot} de

COPYRIGHT AND LICENSE ^

Copyright 2013-2014 Stefan Goebel.

This file is part of Newcomen.

Newcomen is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the license, or (at your option) any later version.

Newcomen is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with Newcomen. If not, see <http://www.gnu.org/licenses/>.