[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: [PATCH] Made commit-email.pl work on both Windows and Unix systems.

From: John Peacock <jpeacock_at_rowman.com>
Date: 2005-01-26 12:25:46 CET

Max Bowsher wrote:
>>>> +# This package exists just to delete the temporary directory.
>>>> +package Temp::Delete;
>>>> +
>>>> +sub new
>>>> +{
>>>> + bless {}, shift;
>>>> +}
>>>
>>>
>>> Is the "shift" doing anything useful?
>>
>>
>> Ahh, you caught me trying to reuse someone else's code without total
>> grokking. I will find out for sure if shift is needed, or just rip it
>> all out in favor of removing the File::Temp requirement and having the
>> user simply configure a variable that points to the preferred temporary
>> directory location.
>
>
> !!!
>
> It would be a bit of a waste to chuck all that code over 1 tiny word!
>
> I'm pretty sure that "bless {};" is sufficient.
>

No, there is a definite point to the two-parameter form of bless(). Though the
canonical way to write that is usually:

sub new
{
     my $proto = shift;
     my $class = ref($proto) || $proto;

     return bless (), $class;
}

The contents of $proto are either going to be an object of the same type, if the
caller was $obj->new(), or it is going to be a string containing the name of the
class this sub is being called by (not necessarily the same class as the
package, since this could be an inherited method). The second line determines
which is which. If you don't provide a class to bless(), it will bless the
object into the current package, which isn't the right thing with inherited classes.

However, in this specific case, there is no concern about subclassing I think,
so the single parameter form of bless() is sufficient.

HTH

John

-- 
John Peacock
Director of Information Research and Technology
Rowman & Littlefield Publishing Group
4720 Boston Way
Lanham, MD 20706
301-459-3366 x.5010
fax 301-429-5747
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Wed Jan 26 12:27:47 2005

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.