[Catalyst] Best way to have the controller do something just	one time
    A. Pagaltzis 
    pagaltzis at gmx.de
       
    Sun Sep  3 14:22:13 CEST 2006
    
    
  
* Jonathan Rockway <jon at jrock.us> [2006-09-03 09:10]:
> As a last resort, if you want the method to be called the first
> time begin() is called, you can simply remove your begin from
> the symbol table the first time through:
> 
> sub begin {
>    ...
>    undef $PACKAGE::{begin}
> }
Uh… you’re undefining the package-global $begin there. I don’t
think that’s what you wanted.
You mean:
    undef *{ __PACKAGE__ . "::begin" };
Or this:
    undef *{ ( caller 0 )[3] };
Or maybe set the whole thing up like so:
    BEGIN {
        my $slot = \*begin;
        *$slot = sub {
            # ...
            undef *$slot;
        }
    }
Saves you from having to index into the symbol table using a
string key.
But whichever you pick, if I were a Java guy, I’d be snickering
even harder at that than at the other hackery.
Regards,
-- 
#Aristotle
*AUTOLOAD=*_;sub _{s/(.*)::(.*)/print$2,(",$\/"," ")[defined wantarray]/e;$1};
&Just->another->Perl->hacker;
    
    
More information about the Catalyst
mailing list