1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 | 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 file "use"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. |
Commit History @c7f58311-b384-49dd-962d-2f695d9b50c9/main
- Fix hashbang in example scripts. gregor herrmann 7 years ago
- Make short description a noun phrase. gregor herrmann 7 years ago
- debian/copyright: switch formatting to Copyright-Format 1.0. gregor herrmann 7 years ago
- Switch to dh(1). gregor herrmann 7 years ago
- Bump debhelper compatibility level to 9. gregor herrmann 7 years ago
- Switch to source format "3.0 (quilt)". gregor herrmann 7 years ago
- Declare compliance with Debian Policy 3.9.8. gregor herrmann 7 years ago
- Mark package as autopkgtest-able. gregor herrmann 7 years ago
- Reformat debian/control with cme gregor herrmann 7 years ago
- update changelog Salvatore Bonaccorso 8 years ago
- debian/control: Use HTTPS transport protocol for Vcs-Git URI Salvatore Bonaccorso 8 years ago
- update changelog Salvatore Bonaccorso 9 years ago
- Update Vcs-Browser URL to cgit web frontend Salvatore Bonaccorso 9 years ago
- update changelog gregor herrmann 10 years ago
- Strip trailing slash from metacpan URLs. gregor herrmann 10 years ago
- update changelog gregor herrmann 11 years ago
- debian/watch: remove obsolete comment. gregor herrmann 11 years ago
- update changelog Salvatore Bonaccorso 11 years ago
- Change search.cpan.org based URIs to metacpan.org based URIs Salvatore Bonaccorso 11 years ago
- update changelog Salvatore Bonaccorso 11 years ago
- Change Vcs-Git to canonical URI (git://anonscm.debian.org) Salvatore Bonaccorso 11 years ago
- update changelog gregor herrmann 11 years ago
- debian/control: update {versioned,alternative} (build) dependencies. gregor herrmann 11 years ago
- debian/control: Convert Vcs-* fields to Git. Ansgar Burchardt 12 years ago
- [mass-commit] change my email address Gregor Herrmann 14 years ago
- [mass-commit] debian/watch: Modify to ignore development releases. Nathan Handler 14 years ago
- [mass commit] switch Vcs-Browser from from WebSVN to ViewSVN Gregor Herrmann 15 years ago
- releasing version 0.04-2 Stephen Gran 16 years ago
- s/UNRELEASED/unstable/ Gregor Herrmann 16 years ago
- debian/rules: let install-stamp target depend on build-stamp. Gregor Herrmann 16 years ago