overload::open - Hooks the native open function
use overload::open 'my_callback'; my %opened_files; sub my_callback { return if !@_; $opened_files{shift}++ } overload::open->prehook_open(\&my_callback); open my $fh, '>', "foo.txt";
This module hooks the native open() and/or sysopen() functions and passes the arguments first to your function and then calls sends it to the provided subroutine functions instead. It does this using XS 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.
open()
sysopen()
This function should work fine if you call open or sysopen inside the callback.
open
sysopen
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.
use overload::open overload::open->prehook_open(\&my_sub)
Runs a hook before open by hooking OP_OPEN. The provided sub reference will be passed the same arguments as open.
OP_OPEN
use overload::open; overload::open->prehook_sysopen(\&my_sub)
Runs a hook before sysopen by hooking OP_SYSOPEN. Passes the same arguments to the provided sub reference as provided to sysopen.
OP_SYSOPEN
Samantha McVey <samantham@posteo.net>
This module is available under the same licences as perl, the Artistic license and the GPL.
To install overload::open, copy and paste the appropriate command in to your terminal.
cpanm
cpanm overload::open
CPAN shell
perl -MCPAN -e shell install overload::open
For more information on module installation, please visit the detailed CPAN module installation guide.