And a link to chromatic's old blog post with the explanations

http://www.modernperlbooks.com/mt/2009/08/the-problems-with-indirect-object-notation.html

Cheers,
  Ynon


On 19 May 2011 14:03, Gabor Szabo <[email protected]> wrote:

> Example 1:
>
> use strict;
> use warnings;
>
> sub f {
>     my $obj = new Module::Debug(1, 2);
> }
>
> f();
>
> Running this script gives:
>
> Can't locate object method "new" via package "Module::Debug" (perhaps
> you forgot to load "Module::Debug"?) at a.pl line 9.
>
> which is about the right error:
>
> Example 2:
>
> use strict;
> use warnings;
>
> sub new {
>    print "in new\n";
> }
>
> sub f {
>     my $obj = new Module::Debug(1, 2);
> }
>
> f();
>
> Running this script gives:
>
> Undefined subroutine &Module::Debug called at a.pl line 9.
>
> Which is just lovely.
>
>
> If I wrote
>
>     my $obj = Module::Debug->new(1, 2);
>
> I would have got the same error,
>
>
> Can't locate object method "new" via package "Module::Debug" (perhaps
> you forgot to load "Module::Debug"?) at a.pl line 9.
>
> regardless of the existence of  'sub new' in the same file.
>
> Gabor
> _______________________________________________
> Perl mailing list
> [email protected]
> http://mail.perl.org.il/mailman/listinfo/perl
>
_______________________________________________
Perl mailing list
[email protected]
http://mail.perl.org.il/mailman/listinfo/perl

Reply via email to