HTML::Template::AssociaUtsee(r3)Contributed Perl DocumenHtTaMtLi:o:nTemplate::Associate(3) NNAAMMEE HTML::Template::Associate - Associate relevant packages with HTML::Tem- plate SSYYNNOOPPSSIISS #Example usage with CGI and FormValidator as the target use CGI qw/:standard/; use Data::FormValidator; use HTML::Template; use HTML::Template::Associate; my $cgi = CGI->new; #for testing purposes we can add some input to our cgi object $cgi->param( q{fullname}, q{John Doe} ); $cgi->param( q{phone}, 6041112222 ); $cgi->param( q{email}, q{invalid@email} ); my $input_profile = { optional => [ qw( company fax country ) ], required => [ qw( fullname phone email address city state zipcode ) ], constraints => { email => "email", fax => "american_phone", phone => "american_phone", zipcode => '/^\s*\d{5}(?:[-]\d{4})?\s*$/', state => "state", }, defaults => { country => "Canada", }, msgs => { prefix=> 'error_', missing => 'Not Here!', invalid => 'Problematic!', invalid_seperator => '
', format => 'ERROR: %s', any_errors => 'some_errors', } }; my $validator = Data::FormValidator->new; my $results = $validator->check ( scalar $cgi->Vars, $input_profile ); my $associate = HTML::Template::Associate->new( { target => 'FormValidator', results => $results, extra_arguments => [ $validator ] } ); #not needed but just illustrated my $template = HTML::Template->new( filename => 'test.tmpl', associate => [ $cgi, $associate ] ); print $template->output; #and in our test.tmpl file we could have Valid Fields:
Field Name:
Field Value:
Missing Fields:
Field Name:
Field Value:
Phone: you supplied is invalid. City name is missing, please fix this. I think is very big country. Message Fields: Field Name:
Field Value:
Our default error message set in the profiling code is: DDEESSCCRRIIPPTTIIOONN HTML::Template::Associate bridges gap between HTML::Template and other modules that can be used in conjunction with it to do something useful together, like for example Data::FormValidator that can verify form inputs. The idea is that every associate object can map required data structure onto the one which corresponds to the one found in HTML::Template. The factory will then instantiate the target class and user can then make it available to HTML::Template via associate argument during object construction. The data structures then become automatically visible to your templates. This module is abstract class it provides no mapping functionality whatsoever, but rather defines common interface to all associate objects underneath it and acts as a object production factory. You should however use this module whenever you wish to access a concrete associate class that provides functionality you desire. UUSSAAGGEE #where $results = Data::FormValidator::Results; for example my $associate = HTML::Template::Associate->new( { target => 'FormValidator', results => $results ); Target is always last portion of your full class name, so if you had HTML::Template::Associate::XYZ the target would be XYZ BBUUGGSS Maybe. If you see any make sure you let me know. SSUUPPPPOORRTT AAUUTTHHOORR Alex Pavlovic alex@taskforce-1.com http://www.taskforce-1.com CCOOPPYYRRIIGGHHTT This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. The full text of the license can be found in the LICENSE file included with this module. SSEEEE AALLSSOO HTML::Template::Associate::FormValidator _p_e_r_l(1). nneeww Usage : my $associate = HTML::Template::Associate->new ( target => 'FormValidator', results => $results ); Purpose : Constructs new associate object Returns : associate instance Argument : Hash of arguments ( target specifying object to be created, results specifying result set, optional extra_arguments specifying additional arguments to be passed inside target object ) Throws : Error in case target does not exist Comments : Please note that target is always last portion of your full class name, so if you had HTML::Template::Associate::XYZ the target would be XYZ ppaarraamm Usage : my $MyParam = $associate->param(q{MyParam}); Purpose : Retrieves param in a form suitable for access by HTML::Template Returns : Single param or arrays suitable for loops Argument : Parameter name and optional value if setting it Throws : Error in case subroutine was not implemented in concrete class Comments : This subroutine should be redefined in concrete class iinniitt Usage : $self->init ( $params ); Purpose : Provides basic initiliazation for the target class Returns : true or false depending on whether initilization was succesful Argument : hash of parameters passed to factory during object construction Throws : Error in case subroutine was not implemented in concrete class Comments : This subroutine should be redefined in concrete class lloogg Purpose : Used internally to warn errors eerrrroorr Purpose : Used internally to die on errors perl v5.8.7 2006-01-04 HTML::Template::Associate(3)