Data::Manager - The Marriage of Message::Stack & Data::Verifier
version 0.10
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');
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
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 attributes 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. This attribute is lazily populated, parsing the Data::Verifier::Results objects. After fetching this attribute any changes to the results will not be reflected in the message stack.
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.
Gets the Data::Verifier::Results object for the specified scope.
Sets the Data::Verifier::Results object 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.
Justin Hunter
Jay Shirley
Brian Cassidy
Cory G Watson <gphat@cpan.org>
This software is copyright (c) 2012 by Cory G Watson.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
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.