Friday, December 3, 2010

Day 3: shorter package names with aliased

Day 1 saved us some characters (for FindBin), but this was just once per script. With aliased you ease typing of long class names:
use aliased 'Rose::HTML::Form::Field::DateTime' => 'DateField';
my $dt = DateField->new(...);

When you leave out the second argument, your alias is 'DateTime' (which would be a bad idea, because this clashes with the CPAN module DateTime).

If you have a complex class structure under a common name space, have a look at aliased::factory.

Links:

1 comment:

  1. Quite a while ago, I also got tired of Typing::Long::Package::Names and started aliasing, though I picked Package::Alias (didn't remember why I picked it over namespace::alias or aliased back then).

    ReplyDelete

Note: Only a member of this blog may post a comment.