celogeek has asked for the wisdom of the Perl Monks concerning the following question:
Hi,
I want to create a role that will be a based for validators.
In my 'CreativesValidator' I have this method :
So here a validator : (ForcedPause)#only there for the validator below which do stuff after build. sub BUILD {} has '_creative_validators' => ( is => 'ro', default => sub { [] }, ); sub register_validator { my ($class, $sub) = @_; $class->can('after')->(BUILD => sub { my ($self) = @_; push @{$self->_creative_validators}, $sub; }); }
is they a cleaner way to do that ? I really want to avoir the copy paste of the register_validator method everywhere. I will have 50 filters or more.use Moo::Role; with 'Weborama::Collect::CreativesValidator'; #you have to define that one requires qw/creatives_validator_publisher_forced_pause_settings/; __PACKAGE__->register_validator(sub { my ( $self, @creatives ) = @_; ... })
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: The best Moo::Role way to do an alias to 'after BUILD'
by tobyink (Canon) on Jan 04, 2013 at 20:57 UTC |
Back to
Seekers of Perl Wisdom