Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
Why should Python have something that Perl doesn't have?

I wondered so myself after reading The Very::Long::Class::Name problem and all its responses.

broquaint's response (using Package::Alias' knowledge about aliasing stashes at compile time) and bart's response (which is the simple assignment of @ISA) made me come up with YAS (Yet Another Solution). Now I'm wondering whether I should upload this to CPAN or not.

    use as;
    use Very::Long::Module::Name as Foo;
    my $foo = Foo->new;

package as; # Make sure we have version info for this module # Make sure we do everything by the book from now on $VERSION = '0.01'; use strict; # Make sure we can do a source filter use Filter::Util::Call (); # Satisfy -require- 1; #--------------------------------------------------------------------- +------ # Methods needed by Perl #--------------------------------------------------------------------- +------ # IN: 1 class (ignored) sub import { # Initialize the fixer upper subroutine # Obtain parameters # Create the alias specification if appropriate # Return possibly adapted string my $fix = sub { my ($package,$rest) = @_; my $alias = $rest =~ s#\bas\s*((?:\w|\w::\w)+)## ? qq(BEGIN {*{"${1}::"} = \\*{"${package}::"}}) : ''; # Package +::Alias approach # qq(BEGIN {\@${1}::ISA = '$package'}) : ''; # bart's version "${alias}use $package$rest"; }; #$fix # Install the filter as an anonymous sub # Initialize status Filter::Util::Call::filter_add( sub { my $status; # If there are still lines to read # Convert the line if it appears to contain a use statement # Return the status if (($status = Filter::Util::Call::filter_read()) > 0) { s#\buse\s+((?:\w|\w::\w)+)([^;]*)#$fix->( $1,$2 )#eg; } $status; } ); } #import #--------------------------------------------------------------------- +------ __END__ =head1 NAME as - load OO module under another name =head1 SYNOPSIS use as; use Very::Long::Module::Name as Foo; my $foo = Foo->new; =head1 DESCRIPTION This module implements a source filter that allows using of modules wi +th a very long name to be used under another name. This is basically achie +ved by creating a dummy module with the short name that inherits from the +module with the large name and which therefore means that there is a run-time penalty for this feature. =head1 INSPIRATION Inspired by bart's response ( +=299082) to a thread about long module names on Perl Monks. =head1 AUTHOR Elizabeth Mattijsen, <>. Please report bugs to <>. =head1 COPYRIGHT Copyright (c) 2003 Elizabeth Mattijsen <>. All rights reserved. This program is free software; you can redistribute it and/ +or modify it under the same terms as Perl itself. =cut

Comments welcome. Particularly about whether the stash alias approach, or the @ISA approach is best. And if you think this would be a waste of CPAN space ;-)


In this response I describe why this proposal, as well as any similarly functioning module such as Package::Alias, suffer from a serious flaw because they change the global namespace. Needless to say, I won;t be uploading this module to CPAN. Everybody can relax again now ;-)

In reply to use Very::Long::Module::Name as Foo; by liz

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others wandering the Monastery: (10)
    As of 2015-11-25 17:53 GMT
    Find Nodes?
      Voting Booth?

      What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

      Results (684 votes), past polls