in reply to Re: Getting rid of "new" (wrong target; perl6)
in thread Getting rid of "new"

Or you could just use aliased:

use aliased 'Long::Class::Name::For::Customer'; my $customer = Customer->new; use aliased 'Worker::Class::With::A::Long::Name' => 'Worker'; my $worker = Worker->new; use aliased 'Class::Name::With::Imports::For::Munger', Munger => @impo +rt_list; my $munger = Munger->new;

Or if you prefer lexicals:

use aliased; my $Customer = alias 'Long::Class::Name::For::Customer'; my $customer = $Customer->new;

This works well because the module author doesn't need to provide support for it. aliased pretty much works for any OO module.

Cheers,
Ovid

New address of my CGI Course.

Replies are listed 'Best First'.
Re^3: Getting rid of "new" (aliased.pm)
by tye (Sage) on Jul 07, 2006 at 18:47 UTC

    I was addressing module authors more than module users. That looks like a nice module for when using modules that don't already support factories [well, the last example -- the prior ones would need to be written as Munger()->new( ... ) to meet my best practices but still wouldn't meet my preference]. Note that your module wouldn't work for a module that actually did get rid of all class methods. (:

    Oh, and that last example would need to be use aliased 'alias'; to meet my best practices. I suspect your module doesn't support that, so I doubt I'll be using it until that gets fixed. :)

    - tye        

      Oh, and that last example would need to be use aliased 'alias'; to meet my best practices. I suspect your module doesn't support that, so I doubt I'll be using it until that gets fixed. :)
      To be honest, the name alias conflicts with a function in the module Data::Alias by xmath, which IMO is much more interesting, to get the rights to use the name.

      I wish perl5 had an easy way to import stuff into names of your own choice.

        It'd be a moderately simple change to Exporter to support:

        use aliased qw( aliasMod=alias ); use Data::Alias qw( aliasData=alias ); use Lexical::Alias qw( lexAlias=alias );

        and one that I've long expected to happen. But you'd have to get aliased.pm to support being passed an argument destined for Exporter.pm, of course.

        - tye        

        I wish perl5 had an easy way to import stuff into names of your own choice

        If only more module authors started using Sub::Exporter...

        -xdg

        Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

      The &alias subroutine is only exported if you don't specify an import list to aliased. That's because it's from a patch by Schwern and lately he's been thinking that exporting things by default is sometimes OK. Since he's the only person who wanted the lexical aliased functionality and it only gets exported if this functionality is requested, I wasn't too worried about it.

      Cheers,
      Ovid

      New address of my CGI Course.