Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/samcv/perl-overload-open
https://github.com/samcv/perl-overload-open
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/samcv/perl-overload-open
- Owner: samcv
- License: other
- Created: 2019-12-07T15:30:40.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2020-01-23T16:46:26.000Z (almost 5 years ago)
- Last Synced: 2023-08-20T23:04:29.625Z (over 1 year ago)
- Language: Perl
- Size: 182 KB
- Stars: 1
- Watchers: 2
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.pod
- Changelog: Changes
- License: LICENSE
Awesome Lists containing this project
README
=head1 NAME
overload::open - Hooks the native open function
=head1 SYNOPSIS
use overload::open;
my %opened_files;
sub my_callback { return if @_ != 2 && @_ != 3; $opened_files{$_[-1]}++ }
overload::open->prehook_open(\&my_callback);
open my $fh, '>', "foo.txt";=head1 DESCRIPTION
This module hooks the native C and/or C functions and passes
the arguments first to callback you provide. It then calls the native open/sysopen.It does this using the XS API and replacing the OP_OPEN/OP_SYSOPEN opcode's
with an XS function. This function will call your provided sub, then once that
returns it will run the original OP.=head1 FEATURES
This function will work fine if you call C or C inside the
callback due to it detecting recursive calls and not calling the callback for
recursive calls.You are not allowed to pass XS subs as the callback because then this could
result in a recursive loop. If you need to do this, wrap the XS function in a
native Perl function.=head1 METHODS
=over
=item prehook_open
use overload::open
overload::open->prehook_open(\&my_sub)Runs a hook before C by hooking C. The provided sub reference
will be passed the same arguments as open.=item prehook_sysopen
use overload::open;
overload::open->prehook_sysopen(\&my_sub)Runs a hook before C by hooking C. Passes the same arguments
to the provided sub reference as provided to sysopen.=item suppress_warnings
overload::open->suppress_warnings(1)
Suppress runtime warnings
=back
=head1 AUTHOR
Samantha McVey
=head1 LICENSE
This module is available under the same licences as perl, the Artistic license and the GPL.