Data::Manager - The Marriage of Message::Stack & Data::Verifier
Data::Manager provides a convenient mechanism for managing multiple Data::Verifier inputs with a single Message::Stack, as well as convenient retrieval of the results of verification.
This module is useful if you have complex forms and you'd prefer to create separate Data::Verifier objects, but want to avoid creating a complex hashref of your own creation to manage things.
It should also be noted that if married with MooseX::Storage, this entire object and it's contents can be serialized. This maybe be useful with Catalyst's flash for storing the results of verification between redirects.
flash
use Data::Manager; use Data::Verifier; my $dm = Data::Manager->new; # Create a verifier for the 'billing_address' my $verifier = Data::Verifier->new( profile => { address1 => { required=> 1, type => 'Str' } # ... more fields } ); $dm->set_verifier('billing_address', $verifier); # Addresses are the same, reuse the verifier $dm->set_verifier('shipping_address', $verifier); my $ship_data = { address1 => { '123 Test Street' }, # ... more }; my $bill_data => { address1 => { '123 Test Street' } # ... more }; $dm->verify('billing_address', $bill_data); $dm->verify('shipping_address', $ship_data); # Later... my $bill_results = $dm->get_results('billing_address'); my $bill_stack = $dm->messages_for_scope('billing_address'); my $ship_results = $dm->get_results('shipping_address'); my $ship_stack = $dm->messages_for_scope('shipping_address);
The Data::Manager object may be serialized thusly:
my $ser = $dm->freeze({ format => 'JSON' }); # later my $dm = Data::Manager->thaw($ser, { format => 'JSON' });
This is possible thanks to the magic of MooseX::Storage. All attribute except verifiers are stored. Serialization causes the verifiers attribute to be set to undefined, as those objects are not serializable.
verifiers
The Message::Stack object for this manager.
HashRef of Data::Verifier::Results objects, keyed by scope.
HashRef of Data::Verifier objects, keyed by scope.
Returns a Message::Stack object containing messages for the specified scope.
Convenience method that checks success on each of the results in this manager. Returns false if any are false.
success
Verify the data against the specified scope. After verification the results and messages will be automatically created and stored. The Data::Verifier::Results class will be returned.
Cory G Watson, <gphat at cpan.org>
<gphat at cpan.org>
Jay Shirley
Brian Cassidy
Copyright 2009 Cory G Watson.
This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.
To install Data::Manager, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Data::Manager
CPAN shell
perl -MCPAN -e shell install Data::Manager
For more information on module installation, please visit the detailed CPAN module installation guide.