App-madeye

 view release on metacpan or  search on metacpan

lib/App/MadEye/Util.pm  view on Meta::CPAN

use List::Util qw/first/;
use YAML ();
use Time::HiRes qw/gettimeofday/;
use Net::SNMP;

sub context () { App::MadEye->context } ## no critic.

sub timeout($$&) {    ## no critic.
    my ( $secs, $msg, $code ) = @_;

    context->log(debug => "run timer: '$msg', $secs");;

    my $last_alarm = 0;
    my $err;
    eval {
        local $SIG{ALRM} = sub { die "Time out error: $msg" };
        $last_alarm = alarm $secs;

        my $start_time = gettimeofday();
            $code->();
        context->log('debug' => "stopwatch: " . (gettimeofday() - $start_time));



( run in 1.460 second using v1.01-cache-2.11-cpan-49f99fa48dc )