From: RedGrittyBrick on
Dr.Ruud wrote:
> RedGrittyBrick wrote:
>
>> my $query = new CGI;
>
> ITYM:
>
> my $cgi = CGI::->new();
>

Yes, I did hesitate over that. In the end I copied what is in the
documentation http://perldoc.perl.org/CGI.html#PROGRAMMING-STYLE.

I've actually forgotten the pitfalls of the, er, deprecated syntax.
Perusing perlobj, perlboot and perltoot didn't help me (though I wasn't
very thorough). Is it anything to do with naming your constructor shazam
and writing `my $instance = shazam OddObject'. Though it works,
presumably as intended, I guess that sort of thing can confuse people &
perl?

So, why is `CGI::->new()' preferred over `CGI->new()' preferred over
`new CGI()'?


--
RGB
From: Dr.Ruud on
RedGrittyBrick wrote:
> Dr.Ruud wrote:
>> RedGrittyBrick wrote:

>>> my $query = new CGI;
>>
>> ITYM:
>>
>> my $cgi = CGI::->new();
>>
>
> Yes, I did hesitate over that. In the end I copied what is in the
> documentation http://perldoc.perl.org/CGI.html#PROGRAMMING-STYLE.
>
> I've actually forgotten the pitfalls of the, er, deprecated syntax.
> Perusing perlobj, perlboot and perltoot didn't help me (though I wasn't
> very thorough). Is it anything to do with naming your constructor shazam
> and writing `my $instance = shazam OddObject'. Though it works,
> presumably as intended, I guess that sort of thing can confuse people &
> perl?
>
> So, why is `CGI::->new()' preferred over `CGI->new()' preferred over
> `new CGI()'?

perl -MData::Dumper -MCGI -wle'
sub new { die "in new" }
sub CGI { die "in CGI" }
my $cgi = CGI::->new;
print Dumper $cgi;
'

$VAR1 = bless( {
'.parameters' => [],
'.charset' => 'ISO-8859-1',
'.fieldnames' => {},
'escape' => 1
}, 'CGI' );

--
Ruud
From: sreservoir on
On 3/29/2010 6:00 PM, RedGrittyBrick wrote:
> Dr.Ruud wrote:
>> RedGrittyBrick wrote:
>>
>>> my $query = new CGI;
>>
>> ITYM:
>>
>> my $cgi = CGI::->new();
>>
>
> Yes, I did hesitate over that. In the end I copied what is in the
> documentation http://perldoc.perl.org/CGI.html#PROGRAMMING-STYLE.
>
> I've actually forgotten the pitfalls of the, er, deprecated syntax.
> Perusing perlobj, perlboot and perltoot didn't help me (though I wasn't
> very thorough). Is it anything to do with naming your constructor shazam
> and writing `my $instance = shazam OddObject'. Though it works,
> presumably as intended, I guess that sort of thing can confuse people &
> perl?
>
> So, why is `CGI::->new()' preferred over `CGI->new()' preferred over
> `new CGI()'?

it isn't, unless someone's stupid enough to make &new or &CGI. it's
just less ambiguous:

new CGI chokes if there is a &new or a &CGI.
CGI->new chokes if there is a &CGI. might do bad things if CGI isn't
require'd or use'd.
'CGI'->new almost always does the right thing.
CGI::->new is syntactic sugar for 'CGI'->new.

actally, foo::bar:: is syntactic sugar for 'foo::bar' except in one
specific case, which usually shouldn't come up.

I use it in tie, mostly.

--

"Six by nine. Forty two."
"That's it. That's all there is."
"I always thought something was fundamentally wrong with the universe."
From: sreservoir on
On 3/29/2010 6:23 PM, Dr.Ruud wrote:
> RedGrittyBrick wrote:
>> Dr.Ruud wrote:
>>> RedGrittyBrick wrote:
>
>>>> my $query = new CGI;
>>>
>>> ITYM:
>>>
>>> my $cgi = CGI::->new();
>>>
>>
>> Yes, I did hesitate over that. In the end I copied what is in the
>> documentation http://perldoc.perl.org/CGI.html#PROGRAMMING-STYLE.
>>
>> I've actually forgotten the pitfalls of the, er, deprecated syntax.
>> Perusing perlobj, perlboot and perltoot didn't help me (though I
>> wasn't very thorough). Is it anything to do with naming your
>> constructor shazam and writing `my $instance = shazam OddObject'.
>> Though it works, presumably as intended, I guess that sort of thing
>> can confuse people & perl?
>>
>> So, why is `CGI::->new()' preferred over `CGI->new()' preferred over
>> `new CGI()'?
>
> perl -MData::Dumper -MCGI -wle'
> sub new { die "in new" }
> sub CGI { die "in CGI" }
> my $cgi = CGI::->new;
> print Dumper $cgi;
> '
>
> $VAR1 = bless( {
> '.parameters' => [],
> '.charset' => 'ISO-8859-1',
> '.fieldnames' => {},
> 'escape' => 1
> }, 'CGI' );

this is horribly contrived and should never happen. but yes, this is
a case where ::-> is preferred.

--

"Six by nine. Forty two."
"That's it. That's all there is."
"I always thought something was fundamentally wrong with the universe."
From: Ben Morrow on

Quoth sreservoir <sreservoir(a)gmail.com>:
> On 3/29/2010 6:23 PM, Dr.Ruud wrote:
> >
> > perl -MData::Dumper -MCGI -wle'
> > sub new { die "in new" }
> > sub CGI { die "in CGI" }
> > my $cgi = CGI::->new;
> > print Dumper $cgi;
> > '
> >
> > $VAR1 = bless( {
> > '.parameters' => [],
> > '.charset' => 'ISO-8859-1',
> > '.fieldnames' => {},
> > 'escape' => 1
> > }, 'CGI' );
>
> this is horribly contrived and should never happen. but yes, this is
> a case where ::-> is preferred.

perldoc aliased.

Ben