Brick::Constraints - Connect the input data to the closures in the pool
use Brick;
Turn a closure into a constraint by providing the bridge between the input hash and code reference.
Call this in your top level generator after you have composed all the pieces you want.
Adapter for Data::FormValidator
sub __make_dfv_constraint # may need to change name to make generic { my( $bucket, $validator, $hash ) = @_;
$hash ||= {}; my @callers = main::__caller_chain_as_list(); my $name = $hash->{profile_name} || $callers[-1]{'sub'} || 'Anonymous'; unless( eval { $validator->isa( ref sub {} ) } or UNIVERSAL::isa( $validator, ref sub {} ) ) { carp( "Argument to $callers[1]{'sub'} must be a code reference [$validator]: $@" ); return $bucket->add_to_bucket( { code => sub {}, name => "Null subroutine", description => "This sub does nothing, because something didn't happen correctly." } ); } my $constraint = $bucket->add_to_bucket( { name => $name, description => "Data::FormValidator constraint sub for $callers[-1]{'sub'}", code => sub { my( $dfv ) = @_; $dfv->name_this( $callers[-1]{'sub'} ); my( $field, $value ) = map { $dfv->${\ "get_current_constraint_$_"} } qw(field value); my $hash_ref = $dfv->get_filtered_data; return unless $validator->( $hash_ref ); return $field; }, } ); $bucket->comprise( $constraint, $validator ); return $constraint; }
TBA
This source is in Github:
https://github.com/briandfoy/brick
brian d foy, <bdfoy@cpan.org>
<bdfoy@cpan.org>
Copyright (c) 2007-2014, brian d foy, All Rights Reserved.
You may redistribute this under the same terms as Perl itself.
To install Brick, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Brick
CPAN shell
perl -MCPAN -e shell install Brick
For more information on module installation, please visit the detailed CPAN module installation guide.