I'm running a Mason site under CGI::Fast and I am having a variable
scoping issue. The essential parts of my CGI handler are: #!/usr/bin/perl -T use strict; use warnings; use CGI::Fast; use CGI::Carp; use HTML::Mason; use Time::HiRes qw|time|; my ($cgi, $runtime, $hits); $::MASON_GLOBALS = [ qw( $cgi $runtime $hits ) ]; my $mason = init_mason(); while ( $cgi = CGI::Fast->new ) { ++$hits; my $start = time(); $mason->handle_request(); $runtime += (time() - $start) * 1000; } # --------------------------------------------------------------------------- # sub init_mason { # initialize the mason object my $cgi_handler; eval { $cgi_handler = HTML::Mason::CGIHandler->new( comp_root => '/my/doc/root/', data_dir => '/my/data/dir/', allow_globals => $::MASON_GLOBALS, ) } or do { croak "Could not create mason cgihandler: $@" }; return $cgi_handler; } The problem is that nothing shows up if I have stats.html under mason with: <p>Total hits <% $hits %></p> </p>Total runtime <% $runtime %></p> I can put the ++$hits in /autohandler and that works, but I can't do that with the runtime because I'm interested in capturing how much time is actually spent inside mason. Referencing it as $main::runtime from inside mason doesn't work either :( Likewise, if I set up %foo as a mason global and set $foo->{bar} = 'baz' in a mason component, the CGI thinks it's undef. So, the ultimate question here is can I get true global variable that are visible to both Mason and the CGI wrapper, and if so, how? I would prefer to keep it all in memory and not store it in a tied hash, rdbms, or similar external data store. |
------------------------------------------------------------------------------ Come build with us! The BlackBerry(R) Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9 - 12, 2009. Register now! http://p.sf.net/sfu/devconference
_______________________________________________ Mason-users mailing list Mason-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mason-users