Changeset 11 for shepherd

Show
Ignore:
Timestamp:
10/04/06 16:31:20 (7 years ago)
Author:
lincoln
Message:

custom DIE() handler to catch die statements in XMLTV and XML::Parser modules because wrapping in eval{} didn't actually work right. bit of an ugly hack but seems to work well.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • shepherd

    r10 r11  
    3030# * --ready  option that says whether config is required? 
    3131 
     32BEGIN { *CORE::GLOBAL::die = \&my_die; } 
    3233use strict; 
    3334use LWP::Simple; 
     
    262263    my $parse_start_time = [gettimeofday]; 
    263264    printf STDERR "SHEPHERD: Started parsing XMLTV from '%s' in '%s' .. any errors below are from parser:\n",$plugin,$output; 
    264     eval { 
    265         local $SIG{__DIE__},  
    266         $plugin_data->{$plugin}->{xmltv} = XMLTV::parsefiles($output); 
    267     }; 
    268     printf STDERR "SHEPHERD: Warning: Parser returned the following: $@\n" if $@; 
     265    eval { $plugin_data->{$plugin}->{xmltv} = XMLTV::parsefiles($output); }; 
    269266    printf STDERR "SHEPHERD: Completed XMLTV parsing from '%s' in %0.2f seconds\n",$plugin,tv_interval($parse_start_time); 
    270267 
     
    11221119} 
    11231120 
     1121# ----------------------------------------- 
     1122# Subs: override handlers for standard perl. 
     1123# ----------------------------------------- 
     1124 
     1125# ugly hack. please don't try this at home kids! 
     1126sub my_die { 
     1127    my ($arg,@rest) = @_; 
     1128    my ($pack,$file,$line,$sub) = caller(1); 
     1129 
     1130    # check if we are in an eval() 
     1131    if ($^S) { 
     1132        printf STDERR "  shepherd caught a die() within eval{} from file $file line $line\n"; 
     1133    } else { 
     1134        if (!ref($arg)) { 
     1135            CORE::die((sprintf "DIE at line %d in file %s: %s\n",$line,$file,(join("",($arg,@rest))))); 
     1136        } else { 
     1137            CORE::die($arg,@rest); 
     1138        } 
     1139    } 
     1140} 
     1141