Acme::Globule - Extensible package-local way to override glob()
version 0.004
# 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 <~>;
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.
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.
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.
Acme::Globule::*, the plugins.
Peter Corlett <abuse@cabal.org.uk>
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.
To install Acme::Globule, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Acme::Globule
CPAN shell
perl -MCPAN -e shell install Acme::Globule
For more information on module installation, please visit the detailed CPAN module installation guide.