NAME
Acme::Globule - Extensible package-local way to override glob()
VERSION
version 0.004
SYNOPSIS
# a simple plugin
package Acme::Globule::Ping;
sub globule {
my($self, $pattern) = @_;
# somebody did <ping> and so we want to return ('pong')
return [ "pong" ] if $pattern eq 'ping';
# they didn't ping, so pass
return;
}
# a simple client
package main;
use Acme::Globule qw( Ping );
# prints "pong'
print <ping>;
# prints the location of your home directory
print <~>;
DESCRIPTION
This package extends glob (and thus <>) to return custom results. It has a plugin mechanism and you define which plugins you wish to use on the import line. Now when you call glob(), these plugins will be tried left-to-right until one claims it, with a fall-through to the standard glob() function.
Each of your packages may use different plugins, and packages that do not import Acme::Globule will get standard glob() behaviour.
Creating a plugin
To create a plugin, create a module Acme::Globule::* and provide a globule() method. The globule method should return an array reference containing the matches, or nothing if it wishes to decline and let the next plugin try it.
BUGS
Any code that uses this module is perverse and therefore contains at least one bug.
This module globally hooks both File::Glob::csh_glob CORE::GLOBAL::glob, and so using this module anywhere in a program will cause all uses of glob() to suffer a slight performance hit even in other modules which do not use it.
glob() within an eval() will probably not do what you expect.
SEE ALSO
Acme::Globule::*, the plugins.
AUTHOR
Peter Corlett <abuse@cabal.org.uk>
COPYRIGHT AND LICENSE
This software is copyright (c) 2011 by Peter Corlett.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.