package AHP::FakeTemplate; =head1 DESCRIPTION Tames CGI::FormBuilder. The class pretends to be a Template in order to catch the CGI::FormBuilder vars passed to process so that we can use them outside of the callback. =head1 SYNPOSIS my $fb_vars; my $form = CGI::FormBuilder->new( ... template => { engine => AHP::FakeTemplate->new_fake(\$fb_vars), type => 'TT2', template => 'ignored', }, ); $form->render(); ... $template->process('my.tt2', { form => $fb_vars, ... }); my.tt2: [% form.start %] [% FOREACH f = form.fields %] [%# "
"; Dumper.dump(f) | html ; "
" %] [% f.required ? "$f.label" : f.label %] [% f.field %] [% f.comment %]
[% IF f.invalid %] Missing or invalid entry. [% END %]
[% END %] [% form.submit %]
[% form.end %] =cut use Carp (); use Template (); @ISA = ('Template'); # It's not really, but C::FB checks # I'd prefer we couldn't act like one use strict; sub new { Carp::croak "$_[0] is not really a Template"; } sub new_fake { my ($class, $target_ref) = @_; return bless $target_ref, $class; } # This sets the reference passed into new_fake sub process { my ($target_ref, $tmpl_ignored, $tt2vars, $tt2output_ref) = @_; $$target_ref = $tt2vars; $$tt2output_ref = ''; return 1; } 1;