Hi Hans,
Hans Dieter Pearcey wrote:
> On Fri, Nov 28, 2008 at 12:17:29PM +0900, Raymond Wan wrote:
>
>> What I have now is:
>>
>> {
>> package HTML::Mason::Commands;
>> use MyUtils;
>> }
>>
>> May I ask what is the purpose of these parentheses? I know they limit
>> scope, so its purpose is to incorporate "MyUtils" into the package
>> HTML::Mason::Commands only and not affect anything else in my handler
>> file (i.e., the file that my handler is in)?
>>
>
> Yes. I used the {} because I didn't know what else was in your handler file,
> and that was the easiest way to limit the scope of my suggestion.
>
> Instead of 'incorporate', it would be more common to say that the purpose is
> to
> import MyUtils into HTML::Mason::Commands. See perldoc Exporter, which then
> points to perlfunc and perlmod. Nothing here is magic; it's just copying
> functions into a new package for You. you could get the same effect by hand
> if
> you did something like this:
>
> # assuming MyUtils exports myfunction and otherfunction, eg. with
> # Exporter, Sub::Exporter, manually, whatever
> *HTML::Mason::Commands::myfunction = \&MyUtils::myfunction;
> *HTML::Mason::Commands::otherfunction = \&MyUtils::otherfunction;
>
> Of course, that's tedious and error-prone, which is why you write 'use
> MyUtils'
> instead, but it helps answer your other question:
>
I see. Thank you for answering my question so well, despite it not
being a Mason question.
Your answer means that if there already is a function called
"myfunction" in HTML::Mason::Commands, I'll either have a conflict or
lose access to it?
And I guess assignment is not a laborious process, but does this mean
that the assignment is done every time a request is made? Or is each
Perl process smart enough to know when the above has been done to
HTML::Mason::Commands before? My module is not very big, but just to
satisfy my curiosity, I wonder if there is a potential performance hit
each time a user makes a request?
>> how do I decide whether they should also be included in or does it not
>> matter?
>>
>
> If they export functions that you want to be usable directly from your
> components (that is, as 'foo()' instead of 'Some::Package::foo()'), they need
> to be 'use'd while inside the HTML::Mason::Commands package. Otherwise they
> don't.
>
Ah, I see -- makes sense; thank you!
Ray
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Mason-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mason-users