]> git.vpit.fr Git - perl/scripts/xchat.git/blobdiff - net.pl
Make sure local_context() runs the code only when the context was found
[perl/scripts/xchat.git] / net.pl
diff --git a/net.pl b/net.pl
index eefa83c79fc59432c4049c5c3af719cda2b31021..80535e18ae7d5035c49051118d740d1c2ccc5b1a 100755 (executable)
--- a/net.pl
+++ b/net.pl
@@ -3,14 +3,15 @@ package Xchat::VPIT::Net;
 use strict;
 use warnings;
 
 use strict;
 use warnings;
 
-use List::Util      qw/max/;
-use Locale::Country qw/code2country/;
+use List::Util      qw<max>;
+use Locale::Country qw<code2country>;
 
 
-use Xchat qw/:all/;
+use Xchat qw<:all>;
 
 use lib get_info 'xchatdir';
 use Xchat::XPI;
 
 use lib get_info 'xchatdir';
 use Xchat::XPI;
-use Xchat::XPI::Net qw/resolve whois/;
+use Xchat::XPI::Net   qw<resolve whois>;
+use Xchat::XPI::Utils qw<save_context>;
 
 our $VERSION = '0.02';
 
 
 our $VERSION = '0.02';
 
@@ -59,7 +60,7 @@ hook_command 'DIG', sub {
 sub dig_print {
  my $p = $_[0];
  my ($context, $req) = @{$_[1]};
 sub dig_print {
  my $p = $_[0];
  my ($context, $req) = @{$_[1]};
- my $oldctxt = get_context;
+ my $guard = save_context;
  set_context $context;
  if ($p) {
   my @a = $p->answer;
  set_context $context;
  if ($p) {
   my @a = $p->answer;
@@ -69,7 +70,7 @@ sub dig_print {
   } else {
    output '*', 'Resolution failed for ' . $req->{host},
           map {
   } else {
    output '*', 'Resolution failed for ' . $req->{host},
           map {
-           $_->mname . ' IN SOA ' . $_->rname . "\n", 
+           $_->mname . ' IN SOA ' . $_->rname . "\n",
            join ' ', 'serial:' . $_->serial, 'ref:' . $_->refresh,
                      'ret:' . $_->retry, 'exp:' . $_->expire,
                      'min:' . $_->minimum . "\n";
            join ' ', 'serial:' . $_->serial, 'ref:' . $_->refresh,
                      'ret:' . $_->retry, 'exp:' . $_->expire,
                      'min:' . $_->minimum . "\n";
@@ -78,7 +79,6 @@ sub dig_print {
  } else {
   print $ph 'Request ' . $req->{host} . " timed out\n";
  }
  } else {
   print $ph 'Request ' . $req->{host} . " timed out\n";
  }
- set_context $oldctxt;
 }
 
 hook_command 'NETWHOIS', sub {
 }
 
 hook_command 'NETWHOIS', sub {
@@ -90,8 +90,8 @@ hook_command 'NETWHOIS', sub {
   my $info = user_info $_;
   my $req = parse_url($info ? $info->{host} : $_);
   whois $req->{host}, \&netwhois_print, [ $context, $req ];
   my $info = user_info $_;
   my $req = parse_url($info ? $info->{host} : $_);
   whois $req->{host}, \&netwhois_print, [ $context, $req ];
- } 
- return EAT_ALL; 
+ }
+ return EAT_ALL;
 }, {
  help_text => 'NETWHOIS <ip(s)/hostname(s)>, retrieve domain/ip information'
 };
 }, {
  help_text => 'NETWHOIS <ip(s)/hostname(s)>, retrieve domain/ip information'
 };
@@ -99,7 +99,7 @@ hook_command 'NETWHOIS', sub {
 sub netwhois_print {
  my $raw = $_[0];
  my ($context, $req) = @{$_[1]};
 sub netwhois_print {
  my $raw = $_[0];
  my ($context, $req) = @{$_[1]};
- my $oldctxt = get_context;
+ my $guard = save_context;
  set_context $context;
  if ($raw) {
   $raw =~ s/.*(Domain|inetnum)/$1/s;
  set_context $context;
  if ($raw) {
   $raw =~ s/.*(Domain|inetnum)/$1/s;
@@ -112,7 +112,6 @@ sub netwhois_print {
  } else {
   output '*', 'No results for ' . $req->{host};
  }
  } else {
   output '*', 'No results for ' . $req->{host};
  }
- set_context $oldctxt;
 }
 
 hook_command 'TLD', sub {
 }
 
 hook_command 'TLD', sub {
@@ -126,17 +125,19 @@ hook_command 'TLD', sub {
   next unless $tld;
   my $name = code2country $tld;
   print $ph $tld . ' is ' . ($name ? $name : 'unknown') . "\n";
   next unless $tld;
   my $name = code2country $tld;
   print $ph $tld . ' is ' . ($name ? $name : 'unknown') . "\n";
- }  
+ }
  return EAT_ALL;
 }, {
  help_text => 'TLD <hostname(s)>, give the TLD text representation of the hosts'
 };
 
  return EAT_ALL;
 }, {
  help_text => 'TLD <hostname(s)>, give the TLD text representation of the hosts'
 };
 
-$ph = new Xchat::XPI name   => 'Networking tools',
-                     tag    => 'Net',
-                     desc   => 'DNS & Whois clients, TLD names',
-                     author => 'Vincent Pit (VPIT)',
-                     email  => 'perl@profvince.com',
-                     url    => 'http://www.profvince.com';
+$ph = Xchat::XPI->new(
+ name   => 'Networking tools',
+ tag    => 'Net',
+ desc   => 'DNS & Whois clients, TLD names',
+ author => 'Vincent Pit (VPIT)',
+ email  => 'perl@profvince.com',
+ url    => 'http://www.profvince.com',
+);
 
 1;
 
 1;