http://www.perlmonks.org?node_id=108160

alfie has asked for the wisdom of the Perl Monks concerning the following question:

Hi!

I faced a quite strange problem today: We are running a mason-powered site which is really a great thing. For I just started with mason just some weeks ago I first used <%method> to hand over some arguments from the component to the autohandler.

Now I found out about the usage of <%attr> and wanted to use that instead. To have a fallback through the transition I wanted to get the attr inside the method to hand it over. The problem is, a method is a subcomponent.

Now, how can I hand over the attr from the current component within a method without having to do such strange things like this:

<%method foo> % return $m->fetch_comp('current.mc')->attr('bar'); </%method>
As you might see this is quite annoying for I have to put the name of the current component into it. But if I use current_comp instead of fetch_comp I get the subcomponent (which is foo in this case), and if I use parent I get the autohandler, not the real component.

So - to put it simple: How can I get to the real component from a sub component? I have tried to dig through the docs at masonhq.com but haven't found anything useful - I guess I'm just blind and it might get worse after searching for several hours. So - any hint would be greatful!
--
use signature; signature(" So long\nAlfie");

Replies are listed 'Best First'.
Re: mason: how to get attr out of a subcomponent?
by blakem (Monsignor) on Aug 27, 2001 at 21:06 UTC
    This is from memory, but I think:
    $m->callers(1)->attr('bar');
    will do the trick....

    -Blake

      Unfortunately, callers(1) gives me the same result like current_comp->parent. With value of 0 I get the current_comp, so this doesn't help at all.

      No one else an idea? Am I out of luck? Unfortunately the #mason on opn seems to be quite dead (it's empty after all) so I think I'll have to bug the mailing lists. Thanks anway for the try.
      --
      use signature; signature(" So long\nAlfie");