[prev in list] [next in list] [prev in thread] [next in thread] 

List:       mason
Subject:    Re: [Mason] Perl OO & Parser Object
From:       Jonathan Swartz <swartz () transbay ! net>
Date:       2000-02-23 14:39:03
[Download RAW message or body]

At 08:09 AM 2/23/00 -0500, Steve Vetzal wrote:
>Greetings,
>
>I'm taking the plunge a little deeper and rebuilding my current projects
>using Perl classes at the core, allowing me to abstract some business logic
>and common dbi code and make it available to several related sites. I
>realize I can do this with a shared component root among the sites, but I
>think the code looks much cleaner as perl objects & methods than calling
>external Mason components. It also seems to be cleaning up the huge number
>of files I've got to content with in that I can wrap many methods under a
>single file - many of my Mason objects are just a few lines long, and a pain
>to debug among several files.
>
>BTW - please feel free to punch holes in my above logic - if I could fit
>several Mason utility components together under a single file, maybe this is
>what I should be doing.

You can put multiple Mason methods in one component (file) using the <%def> 
tag. See http://www.masonhq.com/docs/manual/Devel.html#e_lt_def_i_name_e_gt_.

It is currently possible but tedious, to call one component's methods from
another component.  In 0.82 a new colon syntax will make this easier:

    <& component:method &>
    $m->comp('component:method');

These entities are currently called "subcomponents" but I'm thinking of 
renaming them "methods" (can you tell? :)), since that is more useful 
conceptually and fits with some other OO-type stuff we're planning for 0.82.

On the other hand, it's perfectly reasonable to want to put some logic into
into Perl classes as opposed to components, for the reasons you mention.
You should arrange for the classes to get reloaded whenever they change
(see previous threads on StatINC).

>Anyways, the question I have is this: when calling object methods in Perl,
>I'm finding myself wanting to use $m->out a lot, but of course $m doesn't
>exist in the class. Right now all my output is getting returned from the
>class method and separately output by the mason component with $m->out.
>
>An example is my redirect function:
>
>$output = HTML->redirect(delay=>1, location=>"index.html");
>$m->out($output);
>
>Would it be better to pass the $m object into the class with something like:
>
>HTML->redirect(m=>$m, delay=>1, location=>"index.html");
>
>and then call $m->out in the class method?

Couple of options. First, $m is a global, you can get at it via 
$HTML::Mason::Commands::m. Second, in 0.82, we're planning to tie STDOUT to 
component output, so just using print() inside redirect should work.

Jon



_______________________________________________
Mason maillist  -  Mason@netizen.com.au
http://netizen.com.au/mailman/listinfo/mason

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic