Re: Text::Template and passing in variables; going bug nuts!
> Where I'm getting hosed is that %config and %session have data > I need visible to the Text::Template objects themselves. I've > RTFM'ed until my eyes are pink, and I see no options short of > copying variables wholesale into another Package, but then I > still can't get at them and "use strict" can I? Text::Template has a flexible interface. Put everything into a specific package, or use the HASH option to fill_in(). Use references, not copies. Your sample code has some stuff in it that looks a little scary to me. Do you really want to make %config, %dispatcher, $page, $frame, $command, %session, and %templates into class variables? Maybe instance variables would make more sense. (These are closures variables as well, so they'll keep their values from one request to the next.) And building methods that change class variables instead of actually returning something is kind of obfuscated. But maybe I just don't understand what you're doing from these small snippets. - Perrin
Re: Text::Template and passing in variables; going bug nuts!
Maybe I'm missing something here, but can't you just use use strict; use vars qw(%config %session); or better yet, fully qualify your variables %MyApp::Framework::config; %MyApp::Framework::session; The mod_perl guide has excellent sections on this: http://perl.apache.org/guide/perl.html#Using_Global_Variables_and_Shari http://perl.apache.org/guide/performance.html#Global_vs_Fully_Qualified_Varia Also, there are a couple of useful modules on CPAN for inheriting class data, not sure if they will apply in your case: http://cpan2.org/Asset/display?dist=Class-Data-Inheritable http://cpan2.org/Asset/display?dist=foundation > Where I'm getting hosed is that %config and %session have data > I need visible to the Text::Template objects themselves. I've > RTFM'ed until my eyes are pink, and I see no options short of > copying variables wholesale into another Package, but then I > still can't get at them and "use strict" can I? _ T.J. Mather http://tjmather.com http://cpan2.org/ New CPAN Search Engine http://www.anidea.com/ Digital Asset Management http://www.theinnkeeper.com/Bed and Breakfast Directory
Text::Template and passing in variables; going bug nuts!
Hello: I have a class that I wrote to provide support for multi-form database applications. To use it, I subclass it into something like Exchange::Admin. Now all the session cookie and state data code I need happens in the background. Now, I want to extend MyApp::Framework with Text::Template like this: package MyApp::Framework; use Text::Template; my (%config, %dispatcher, $page, $frame, $command, %session, %templates); sub new { my $class = shift; my $self = {}; $bless ($self, $class); $self->get_configured; Apache->push_handlers(PerlChildInitHandler => \&child_init); } sub get_configured { my ($self ) = @_; # load %config, %dispatcher, and %templates hashes in here. } sub child_init { my ($self) = @_; $db{dbh} = DBI->connect($config{DBI_DSN}, $config{DBI_User}, $config{DBI_Passwd}); # prepare sql here } sub handler ($$) { my ($self, $q) = @_; my $r = Apache::Request->new($q); # session magic here my $preprocessor = $dispatch_table{$page}{$frame}{$command}; $self->$preprocessor($r); #modifies class variables $r->content_type('text/html'); $r->send_hhttp_headers; $templates{$page}{$frame}->fill_in; # more session cleanup magic here return OK; } Where I'm getting hosed is that %config and %session have data I need visible to the Text::Template objects themselves. I've RTFM'ed until my eyes are pink, and I see no options short of copying variables wholesale into another Package, but then I still can't get at them and "use strict" can I? I'm totally out of ideas. Can anyone suggest some useful stratagems? --Christopher Everett