Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Ovid (2709)

Ovid
  (email not shown publicly)
http://publius-ovidius.livejournal.com/
AOL IM: ovidperl (Add Buddy, Send Message)

Stuff with the Perl Foundation. A couple of patches in the Perl core. A few CPAN modules. That about sums it up.

Journal of Ovid (2709)

Sunday October 30, 2005
08:53 PM

Nice benefit of "aliased"

[ #27377 ]

If you haven't checked out my aliased module, you really should. One of the pleasant side effects of this module is how it avoids accidental use of indirect method syntax. I had the following:

use Games::World;
can_ok 'Games::World', 'dump_vocabulary';
is Games::World->dump_vocabulary, $vocabulary,
    '... and it should return the correct vocabulary';

That fails with the following error message:

Can't locate object method "is" via package "Games::World" at ...

That's really annoying. It's particularly annoying because it's trying to use indirect method syntax even though I'm clearly trying to call the dump_vocabulary method. To make that work, I have to use parentheses with is():

use Games::World;
can_ok 'Games::World', 'dump_vocabulary';
is(Games::World->dump_vocabulary, $vocabulary,
    '... and it should return the correct vocabulary');

However, aliased gives me two benefits. The first, of course, is shorter class names. The second is that it does not trigger spurious indirect method invocation (an annoying source of subtle bugs).

use aliased 'Games::World';
can_ok World, 'dump_vocabulary';
is World->dump_vocabulary, $vocabulary,
    '... and it should return the correct vocabulary';

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • Do note that you can disambiguate that without parens, if you are so inclined.

    can_ok 'Games::World', 'dump_vocabulary';
    is +Games::World->dump_vocabulary, $vocabulary,
        '... and it should return the correct vocabulary';