-
-
02 Aug 2007 14:30:44 UTC
- Distribution: Filter-EOF
- Module version: 0.04
- Source (raw)
- Browse (raw)
- Changes
- How to Contribute
- Issues (1)
- Testers (1156 / 2 / 2)
- Kwalitee
Bus factor: 1- 97.92% Coverage
- License: perl_5
- Activity
24 month- Tools
- Download (14.89KB)
- MetaCPAN Explorer
- Permissions
- Subscribe to distribution
- Permalinks
- This version
- Latest version
and 1 contributors-
Robert 'phaylon' Sedlacek
- Dependencies
- Carp
- Filter::Util::Call
- and possibly others
- Reverse dependencies
- CPAN Testers List
- Dependency graph
NAME
Filter::EOF - Run a callback after a file has been compiled
VERSION
0.04
SYNOPSIS
package MyPackage; use warnings; use strict; use Filter::EOF; sub import { my ($class, @args) = @_; my $caller = scalar caller; # set the COMPILE_TIME package var to a false value # when the file was compiled Filter::EOF->on_eof_call(sub { no strict 'refs'; ${ $caller . '::COMPILE_TIME' } = 0; }); # set the COMPILE_TIME package var to a true value when # we start compiling it. { no strict 'refs'; ${ $caller . '::COMPILE_TIME' } = 1; } } 1; ... package MyUsingPackage; use warnings; use strict; our $COMPILE_TIME; use MyPackage; # prints 'yes' BEGIN { print +( $COMPILE_TIME ? 'yes' : 'no' ), "\n" } # prints 'no' print +( $COMPILE_TIME ? 'yes' : 'no' ), "\n"; 1;
DESCRIPTION
This module utilises Perl's source filters to provide you with a mechanism to run some code after a file using your module has been processed.
METHODS
import( @functions )
Currently, only a function equivalent of the
on_eof_call
method is provided for export.use Filter::EOF qw( on_eof_call ); sub import { my ($class) = @_; ... on_eof_call { ... }; } ...
on_eof_call( $code_ref )
Call this method in your own
import
method to register a code reference that should be called when the fileuse
ing yours was compiled.The code reference will get a scalar reference as first argument to an empty string. if you change this string to something else, it will be appended at the end of the source.
# call C<some_function()> after runtime. Filter->on_eof_call(sub { my $append = shift; $$append .= '; some_function(); 1;'; });
EXPORTS
on_eof_call
You can optionally import the
on_eof_call
function into your namespace.EXAMPLES
You can find the example mentioned in "SYNOPSIS" in the distribution directory
examples/synopsis/
.SEE ALSO
Filter::Call::Util, "Exporting without using Exporter's import method" in Exporter
AUTHOR AND COPYRIGHT
Robert 'phaylon' Sedlacek -
<rs@474.at>
. Many thanks to Matt S Trout for the idea and inspirations on this module.LICENSE
This program is free software; you can redistribute it and/or modify it under the same terms as perl itself.
Module Install Instructions
To install Filter::EOF, copy and paste the appropriate command in to your terminal.
cpanm Filter::EOF
perl -MCPAN -e shell install Filter::EOF
For more information on module installation, please visit the detailed CPAN module installation guide.