in reply to Mason Interp Perl string

I said I was going to let this go...but I didn't...and boy I wish I had.

I can sum up my findings here. Consider this starting point...

package Mason::TestHandler; use strict; use warnings; use HTML::Mason::ApacheHandler; our @ISA = qw(HTML::Mason::ApacheHandler); sub handler { my($r) = @_; # Remember, $r contains a virtual filename (does not exist on disk +). my @fileList = someMagicToGetFiles($r); my $testPath = $fileList[0]; # ... VARIOUS ATTEMPTS GO HERE ... # }

Then I tried to get it to work a bunch of different ways...

... my $ah = HTML::Mason::ApacheHandler->make_ah($r); my $mi = $ah->interp; my $output = $mi->exec($testPath);

This will fail with error "[error] Mandatory parameter 'ah' missing in call to MasonX::Request::WithApacheSession->new()\n"

... $r->filename($testPath); my $ah = HTML::Mason::ApacheHandler->make_ah($r); my $output = $ah->prepare_request($r);

This will fail with error "[Mason] Cannot resolve file to component: /somepath/realfile.js (is file outside component root?) at /usr/lib/perl5/site_perl/5.8.8/HTML/Mason/ApacheHandler.pm line 852."

I then tried making the path start with the exact CompRoot listed in my config (different route to same file). That gives me the error "[error] Can't locate object method "param" via package "Apache::Filter" at /usr/lib/perl5/site_perl/5.8.8/HTML/Mason/ApacheHandler.pm line 996.\n"

I've tried different variations of the same theme, with one of these errors coming up each time. The only way I've gotten the interpreter to work is by directly creating it:

... use HTML::Mason::Interp; my $mi = HTML::Mason::Interp->new(data_dir => '/a/good/data/dir/' +, comp_root => '/a/good/comp/root/ +', ); my $c = $mi->make_component(comp_file => $testPath ); my $output = $mi->exec($c);

Because my $r is valid, I can even snarf the values I need out of it. However, one of the key goals was to have valid session information. So if I add the request_class and session_class to the above, I am still missing ah (see first attempt). This ah error comes up a lot.

Sigh. So I am completely out of ideas.

Replies are listed 'Best First'.
Re^2: Mason Interp Perl string
by SleepyJay (Beadle) on Feb 27, 2012 at 23:37 UTC

    Ok. I got it. Finally. I had given up, but one night on my drive home I got a crazy idea...and it worked.

    I created a Mason file that produces JavaScript, call it loader.mjs, that takes at least the "/somepath/foo.dynjs" as an argument in the query string. This satisfies the Mason handler's desire to have a physical file. The Mason code inside of the loader.mjs file calls the library that resolves the dynjs file, and I can $m->comp that result, and it all just simply works--session intact, etc.

    In retrospect, of course this is the easiest way to do it. And, once of thought of it, it took me hardly 20 minutes to hook all of the pieces together in the correct way (after the hours over several days trying to make it work the other way above). Sigh.

    jason.

      no help from the mason list?