1 package Xchat::VPIT::Tools;
11 use lib get_info 'xchatdir';
14 our $VERSION = '0.04';
19 $Data::Dumper::Indent = 1;
20 $Data::Dumper::Sortkeys = 1;
23 hook_command 'TC', sub {
24 my $oldctxt = get_context;
25 for (get_list 'channels') {
26 set_context $_->{context};
27 command 'GUI COLOR 0';
32 help_text => 'TC, reset all tab color indicators'
35 sub d { return Dumper @_; }
36 sub dp { print $ph Dumper(@_), "\n" }
38 sub warneval { print $ph 'Warning: ' . (join ' ', @ _) }
40 hook_command 'PERL', sub {
41 return EAT_ALL unless defined $_[0][1];
42 if ($_[0][1] eq '-o') {
43 return EAT_ALL unless defined $_[1][2];
44 local $SIG{__WARN__} = \&warneval;
45 my @result = grep defined, (eval $_[1][2]);
46 local $SIG{__WARN__} = 'DEFAULT';
49 print $ph "Error: $@\n";
51 command join ' ', 'MSG', get_info('channel'), @result;
53 print $ph "No output\n";
56 local $SIG{__WARN__} = \&warneval;
57 my @result = eval $_[1][1];
58 local $SIG{__WARN__} = 'DEFAULT';
61 print $ph "Error: $@\n";
64 @result = ('(empty)') unless @result;
65 my ($c, @scalars) = (0);
67 (defined || (push @scalars, '(undef)') && 0)
68 && (ref || (push @scalars, $_) && 0)
69 && ((push @scalars, '$REF' . ++$c) || 1)
72 local $Data::Dumper::Varname = 'REF';
73 print $ph 'Return: ', (join ' | ', @scalars), "\n", d @refs;
78 help_text => 'PERL [-o] <perlexp>, evalute the expression with Perl'
81 hook_command 'URIESCAPE', sub {
82 return EAT_ALL unless defined $_[0][1];
83 my ($uri, $out, $protect);
84 if ($_[0][1] eq '-o') {
87 } elsif ($_[0][1] eq '-p') {
93 $uri = encode get_info('charset'), $uri;
94 $uri =~ s/([^A-Za-z0-9\-_.!~*'():\/])/sprintf("%%%02X",ord($1))/ge;
96 command 'SAY ' . $uri;
98 $uri =~ s/%/%%/g if $protect;
103 help_text => 'URIESCAPE [-o|-p] <uri>, escape unsafe characters in the URI'
106 hook_command 'WIDE', sub {
108 return EAT_ALL unless defined $txt;
109 $txt =~ s/([\x21-\x7e])/chr 0xfee0 + ord $1/ge;
110 command 'SAY ' . $txt;
113 help_text => 'WIDE <text>, say text in wide unicode characters'
116 $ph = new Xchat::XPI name => 'Misc tools',
118 desc => 'Perl interpretor, URI escaper',
119 author => 'Vincent Pit (VPIT)',
120 email => 'perl@profvince.com',
121 url => 'http://www.profvince.com';