David Schmidt
unread,Jun 10, 2013, 4:47:08 AM6/10/13Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to formh...@googlegroups.com
I copied HFH::Moose::Role to HFH::Moose::RoleParameterized and
replaced every occurrence of "Moose::Roole" with
"MooseX::Role::Parameterized"
I wrote an example of a HFH moose role that has a parameter "name"
defaulting to "variable"
It almost works. The parameterized role is consumed. but the role is
consumed twice, once with the parameter i passed to the role and once
with the default.
package EPPlication::Role::Form::Step::Variable;
use HTML::FormHandler::Moose::RoleParameterized;
parameter 'name' => (
isa => 'Str',
default => 'variable',
);
role {
my $params = shift;
my $name = $params->name;
has_field $name => (
type => 'Text',
);
};
no HTML::FormHandler::Moose::RoleParameterized;
1;
# Usage
package EPPlication::Form::Step::VarVal;
use HTML::FormHandler::Moose;
extends 'EPPlication::Form::Step::Base';
with
'EPPlication::Role::Form::Step::Value',
'EPPlication::Role::Form::Step::Variable' => { name => 'bar' },
;
1;
package HTML::FormHandler::Moose::RoleParameterized;
# ABSTRACT: to add sugar to roles
use MooseX::Role::Parameterized;
use Moose::Exporter;
Moose::Exporter->setup_import_methods(
with_caller => [ 'has_field', 'has_block', 'apply' ],
also => 'MooseX::Role::Parameterized',
);
sub init_meta {
my $class = shift;
my %options = @_;
MooseX::Role::Parameterized->init_meta(%options);
my $meta = Moose::Util::MetaRole::apply_metaroles(
for => $options{for_class},
role_metaroles => { role => ['HTML::FormHandler::Meta::Role'] }
);
return $meta;
}
sub has_field {
my ( $class, $name, %options ) = @_;
$class->meta->add_to_field_list( { name => $name, %options } );
}
sub has_block {
my ( $class, $name, %options ) = @_;
$class->meta->add_to_block_list( { name => $name, %options } );
}
sub apply {
my ( $class, $arrayref ) = @_;
$class->meta->add_to_apply_list( @{$arrayref} );
}
use namespace::autoclean;
1;