Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

autotie CGI::SSI to CGI::Application output

by ryan (Pilgrim)
on Feb 06, 2003 at 07:43 UTC ( #233073=perlquestion: print w/replies, xml ) Need Help??
ryan has asked for the wisdom of the Perl Monks concerning the following question:

I want to autotie CGI::SSI in some way to the output of my CGI::Application module.

For a normal CGI I would do the following and it would interpret any SSI tags in whatever the script outputs before it goes to the browser:

use CGI::SSI (autotie => STDOUT);
When I try this in a CGI::Application module it reports errors about file handles such as:
Failed to copy the filehandle (ATRACK::STDOUT): Invalid argument at /u +sr/share/perl5/CGI/SSI.pm line 74.
I'll be the first to admit I don't know how CGI::Application handles STDOUT, or what filehandle it uses to do it's magic, do I need to autotie it to some other special file handle? I've had a look through the source for any clues, but it is beyond me. Can anyone suggest how I could achieve this or if I'm wasting my time trying?

Thanks,

Ryan

Replies are listed 'Best First'.
Re: autotie CGI::SSI to CGI::Application output
by ryan (Pilgrim) on Feb 13, 2003 at 05:14 UTC
    OK, I'll have a go at my own question then :)

    The reason for this is the HTML templates were rather 'pretty' and had a heap of nested tables in them that was just too much code to duplicate. So I wanted a way to call a function from within the template that can accept a parameter and produce the code for the table with the parameter as the title of the table.

    In the end I found that HTML::Template::Expr can do this so I modified CGI::Application to use HTML::Template::Expr instead of HTML::Template and it all went well. It was just a simple substitution of the module name in two spots.

    I know this is not a good use of templating technology, both I and the HTML::Template author agree there - but this particular case called for it.

    The actual code in the CGI::Application module was a declaration of the template functions and their related subs:

    HTML::Template::Expr->register_function(box => \&box); sub box { #read in other templates to costruct table header #use parameters to decide if it is the start or the #end of the box and what title to use etc. }
    Then in the templates:
    <!-- TMPL_VAR expr="box('box-start','Table title')" --> table contents here <!-- TMPL_VAR expr="box('box-end')" -->
    Ugly, but it works and reduces the template code size to about half :)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://233073]
Approved by blokhead
help
Chatterbox?
[stevieb]: so, it's -34c today, and some of my water pipes are frozen and one burst. sigh
[stevieb]: it doesn't seem as though "there's an app for that"
[ambrus]: burst water pipe sucks
[Corion]: ambrus: Ugh - yes, that really sucks!
[stevieb]: good thing is that both sides of the break are completely frozen, so I was able to shut off the water to the building before any water leaks. I told the landlord last year to insulate that specific area better
[Corion]: stevieb: Our SV overlords don't know what "frozen pipe" means and think it's something like "frozen yogurt"
[ambrus]: huh... what does "SV" mean there?

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (6)
As of 2016-12-08 18:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (144 votes). Check out past polls.