9 More Discussions You Might Find Interesting
1. UNIX for Advanced & Expert Users
Heyas
I'm currently trying to make 'make uninstall' work properly, as it doesnt remove empty directories.
To do so, i've applied:
uninstall-hook:
if test -d $docdir; then rmdir $docdir; fi
As stated (example) in automake - 'make uninstall': Howto remove empty directories - Stack... (2 Replies)
Discussion started by: sea
2 Replies
2. Shell Programming and Scripting
I'm writing a script to use as a LoginHook for my Mac users. As part of this script, I need to write to a location in their home directory, but I can't seem to access the path - at this point in the login process, $HOME is empty and ~ gives the path to root's home. Unfortunately, I can't just do... (1 Reply)
Discussion started by: blondepianist
1 Replies
3. UNIX for Advanced & Expert Users
iam trying to built a firewall.so i have used netfilter for it.
in function main_hook sock_buff is returning null and in my log file continuously "sock buff null" is printed plse help to solve this problem..
(using print_string iam printing strings on current terminal (terminal we ping))
... (1 Reply)
Discussion started by: pavan6754
1 Replies
4. Programming
hello,
Im trying to create some kind of a file change hook on unix machines (should be generic if possible).
Do any of you know how can i write some code that will trigger whenever a file is being modified and then will approve the modifications, or throw an exception if the new content of... (2 Replies)
Discussion started by: ErezB
2 Replies
5. UNIX for Dummies Questions & Answers
Hi All,
One more time (!). I have started a contract job and am looking for any online tutorials for AIX, 5 or 5L, just an overview to brush up on system administration, security, networking, etc. with the newer and Linux linked versions.
Several people on the web have indicated in other... (1 Reply)
Discussion started by: jeffpas
1 Replies
6. UNIX for Dummies Questions & Answers
Hi All,
There has been talk about UNIX self-paced online tutorials written by Gary Hook, and that they are very good, specifically AIX.
I am looking for the latest version of AIX, administration, tuning, networking, etc. (Like version 5 or 5L.) Basics to mid-range.
I have searched all... (0 Replies)
Discussion started by: jeffpas
0 Replies
7. Solaris
I'm not familiar with this particular machine and it's baffling me. For those that are familar with the workstation, allow me to paint a picture. If you were looking down on the machine (open) you would see the main board and then a riser board. On the left side of the riser board are jacks... (1 Reply)
Discussion started by: silversaleen68
1 Replies
8. Solaris
Background:
DEDS is used to exchange files between Our Client and outside world. It is running on Sun v480 server OS 5.8. The files can come into or go out from various directories configured for various interfaces and come from both Our Client side as well as outside world.
Requirement:
... (0 Replies)
Discussion started by: kdhana
0 Replies
9. Linux
I have desktop with both windows and fedora core 2 installed on it which I have also hooked up to my psion 5mx palm device that is stored in the windows drive... and i just access the files by mounting them onto my linux drive.. now I have a laptop too .. with the same directories as the linux... (7 Replies)
Discussion started by: moxxx68
7 Replies
Hook::WrapSub(3pm) User Contributed Perl Documentation Hook::WrapSub(3pm)
NAME
Hook::WrapSub - wrap subs with pre- and post-call hooks
SYNOPSIS
use Hook::WrapSub qw( wrap_subs unwrap_subs );
wrap_subs &before, 'some_func', 'another_func', &after;
unwrap_subs 'some_func';
DESCRIPTION
wrap_subs
This function enables intercepting a call to any named function; handlers may be added both before and after the call to the intercepted
function.
For example:
wrap_subs &before, 'some_func', &after;
In this case, whenever the sub named 'some_func' is called, the &before sub is called first, and the &after sub is called afterwards.
These are both optional. If you only want to intercept the call beforehand:
wrap_subs &before, 'some_func';
You may pass more than one sub name:
wrap_subs &before, 'foo', 'bar', 'baz', &after;
and each one will have the same hooks applied.
The sub names may be qualified. Any unqualified names are assumed to reside in the package of the caller.
The &before sub and the &after sub are both passed the argument list which is destined for the wrapped sub. This can be inspected, and
even altered, in the &before sub:
sub before {
ref($_[1]) && $_[1] =~ /ARRAY/
or croak "2nd arg must be an array-ref!";
@_ or @_ = qw( default values );
# if no args passed, insert some default values
}
The &after sub is also passed this list. Modifications to it will (obviously) not be seen by the wrapped sub, but the caller will see the
changes, if it happens to be looking.
Here's an example that causes a certain method call to be redirected to a specific object. (Note, we use splice to change $_[0], because
assigning directly to $_[0] would cause the change to be visible to the caller, due to the magical aliasing nature of @_.)
my $handler_object = new MyClass;
Hook::WrapSub::wrap_subs
sub { splice @_, 0, 1, $handler_object },
'MyClass::some_method';
my $other_object = new MyClass;
$other_object->some_method;
# even though the method is invoked on
# $other_object, it will actually be executed
# with a 0'th argument = $handler_obj,
# as arranged by the pre-call hook sub.
Package Variables
There are some Hook::WrapSub package variables defined, which the &before and &after subs may inspect.
$Hook::WrapSub::name
This is the fully qualified name of the wrapped sub.
@Hook::WrapSub::caller
This is a list which strongly resembles the result of a call to the built-in function "caller"; it is provided because calling "caller"
will in fact produce confusing results; if your sub is inclined to call "caller", have it look at this variable instead.
@Hook::WrapSub::result
This contains the result of the call to the wrapped sub. It is empty in the &before sub. In the &after sub, it will be empty if the
sub was called in a void context, it will contain one value if the sub was called in a scalar context; otherwise, it may have any
number of elements. Note that the &after function is not prevented from modifying the contents of this array; any such modifications
will be seen by the caller!
This simple example shows how Hook::WrapSub can be used to log certain subroutine calls:
sub before {
print STDERR <<" EOF";
About to call $Hook::WrapSub::name( @_ );
Wantarray=$Hook::WrapSub::caller[5]
EOF
}
sub after {
print STDERR <<" EOF";
Called $Hook::WrapSub::name( @_ );
Result=( @Hook::WrapSub::result )
EOF
@Hook::WrapSub::result
or @Hook::WrapSub::result = qw( default return );
# if the sub failed to return something...
}
Much more elaborate uses are possible. Here's one one way it could be used with database operations:
my $dbh; # initialized elsewhere.
wrap_subs
sub {
$dbh->checkpoint
},
'MyDb::update',
'MyDb::delete',
sub {
# examine result of sub call:
if ( $Hook::WrapSub::result[0] ) {
# success
$dbh->commit;
}
else {
# failure
$dbh->rollback;
}
};
unwrap_subs
This removes the most recent wrapping of the named subs.
NOTE: Any given sub may be wrapped an unlimited number of times. A "stack" of the wrappings is maintained internally. wrap_subs "pushes"
a wrapping, and unwrap_subs "pops".
AUTHOR
jdporter@min.net (John Porter)
COPYRIGHT
This is free software. This software may be modified and/or distributed under the same terms as Perl itself.
perl v5.10.1 2009-12-09 Hook::WrapSub(3pm)