[Maypole] CGI::Maypole issues (continued)

From: Gabor Szabo (gabor at perl.org.il)
Date: Sat Sep 11 2004 - 14:00:04 BST


Again, it might be only me but I needed the following things in order
to make CGI::Maypole work and these were also the most difficult issues
as it was hard *for me* to find documentation for these

1) put the setup in BEGIN block in order to be able to be able
   to use the :Exported attribute
2) override get_template_root
3) override send_output if you wan to set cookies or otherwis manipulate
   the header
4) The Maypole::View::Base patch I mentioned in the previous message.

use base 'CGI::Maypole';
BEGIN {
    # must be in the BEGIN block to faciliate the attributes thing...
    MP->setup("dbi:SQLite:dbname=../../db/cpants.db");
}

# this is not strictly CGI::Maypole issue but it can help if
# the live server has differnt hostname than the development server
# which is usually the case
MP->config->{uri_base} = "http://$ENV{HTTP_HOST}/";

# you must provide this function in case of CGI::Maypole
# and this was you don't have to worry at deployment time.
sub get_template_root {
    if ($ENV{HTTP_HOST} eq "cpants.szabgab.com") {
        return "/web/cpants/www/templates";
    }
    return "/home/gabor/cpants/www/templates";
}

# override a function of CGI::Maypole in order to be able to set cookie
sub send_output {
    my $r = shift;
    #warn "send_output\n";

    print $r->{cgi}->header(-type => $r->{content_type},
                        -content_length => length $r->{output},
                        -cookie => $r->{cookie},
            );
    print $r->{output};
}

All this using Maypole 1.7.

Gabor

_______________________________________________
maypole mailing list
maypole at lists.netthink.co.uk
http://lists.netthink.co.uk/listinfo/maypole



This archive was generated by hypermail 2.1.3 : Thu Feb 24 2005 - 22:25:56 GMT