<?xml version="1.0" encoding="windows-1252"?>
<node id="299107" title="use Very::Long::Module::Name as Foo;" created="2003-10-14 09:56:57" updated="2005-08-15 12:08:38">
<type id="120">
perlmeditation</type>
<author id="272239">
liz</author>
<data>
<field name="doctext">
Why should Python have something that Perl doesn't have?
&lt;P&gt;
I wondered so myself after reading [id://298944] and all its responses.
&lt;P&gt;
[broquaint]'s [id://298987|response] (using [cpan://Package::Alias]' knowledge about aliasing stashes at compile time) and [bart]'s [id://299082|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.
&lt;P&gt;
&lt;DL&gt;
&lt;DT&gt;&lt;B&gt;SYNOPSIS&lt;/B&gt;
&lt;DD&gt;&lt;pre&gt;
    use as;
    use Very::Long::Module::Name as Foo;
    my $foo = Foo-&gt;new;
&lt;/pre&gt;&lt;/DL&gt;
&lt;P&gt;
&lt;readmore&gt;
&lt;code&gt;
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()) &gt; 0) {
            s#\buse\s+((?:\w|\w::\w)+)([^;]*)#$fix-&gt;( $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-&gt;new;

=head1 DESCRIPTION

This module implements a source filter that allows using of modules with a
very long name to be used under another name.  This is basically achieved
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 (http://www.perlmonks.org/index.pl?node_id=299082)
to a thread about long module names on Perl Monks.

=head1 AUTHOR

Elizabeth Mattijsen, &lt;liz@dijkmat.nl&gt;.

Please report bugs to &lt;perlbugs@dijkmat.nl&gt;.

=head1 COPYRIGHT

Copyright (c) 2003 Elizabeth Mattijsen &lt;liz@dijkmat.nl&gt;. All rights
reserved.  This program is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.

=cut
&lt;/code&gt;
&lt;/readmore&gt;
&lt;P&gt;
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  ;-)
&lt;P&gt;
Liz
&lt;P&gt;
&lt;B&gt;Update&lt;/B&gt;:&lt;BR&gt;
In [id://299206|this response] I describe why this proposal, as well as any similarly functioning module such as [cpan://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   ;-)</field>
</data>
</node>
