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 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, . 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