[tpm] Lightning Talk lineup
abram hindle
abram.hindle at softwareprocess.us
Sat Oct 4 06:49:06 PDT 2008
This is really dangerous behaviour. Especially in OO code.
When you're doing OO you have to remember that:
* The method might not be defined in this package!
** You might've inherited, or it was auto-generated/auto-run by autoload
* OO in Perl uses Dynamic Dispatch,
** you should dispatch off your object
*** What if you subclassed the object?
* If you sublcass your alias won't work if you overload what was aliased!
I've provided some example code about the issue.
abram
On Fri, 3 Oct 2008, Alexandru Capsa wrote:
> Well, when you have to call a method defined later in the source file you
> have to use '&' or use the brackets. Example:
>
> package foo;
>
> sub my_method {
> my $b = some_method;
> }
> sub some_method {
> return "something";
> }
>
> The above will fail, Perl will think of "some_method" as just another bare
> word. But if you write:
>
> my $b = &some_method;
> or
> my $b = some_method();
>
> everything will work. Of course, you can also define some_method before
> my_method.
>
> Cheers,
> Alex
>
>
> On Fri, Oct 3, 2008 at 2:20 PM, Dave Doyle <dave.s.doyle at gmail.com> wrote:
>
>> ...
>>
>> Dammit.
>>
>>
>> On Fri, Oct 3, 2008 at 1:39 PM, Richard Dice <rdice at pobox.com> wrote:
>>
>>>
>>>>
>>>> But then Richard broke my head with:
>>>>
>>>> sub a {
>>>> &b
>>>> }
>>>>
>>>
>>> Jon Orwant schooled me with this one back in '97.
>>>
>>>
>>>> My jaw literally hit the table. I'd also not know the & invocation style
>>>> (without brackets) automatically passed @_ into the sub. I'd thought that &
>>>> is soooo Perl 4 and beneath my notice. Whoops. Two characters. Two bloody
>>>> characters to my 21.
>>>>
>>>
>>> Of course, '&' is necessary when defererencing a coderef, but the context
>>> is different I'll admit.
>>>
>>>
>>>> Got the job though. :)
>>>>
>>>
>>> Yeah, about that. We should talk...
>>>
>>> Cheers,
>>> - Richard
>>>
>>>
>>
>>
>> --
>> dave.s.doyle at gmail.com
>>
>> _______________________________________________
>> toronto-pm mailing list
>> toronto-pm at pm.org
>> http://mail.pm.org/mailman/listinfo/toronto-pm
>>
>>
>
>
> --
> Alexandru Capsa
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test2.pl
Type: text/x-perl
Size: 1908 bytes
Desc:
URL: <http://mail.pm.org/pipermail/toronto-pm/attachments/20081004/9d241e42/attachment.bin>
More information about the toronto-pm
mailing list