1 package Xchat::XPI::Utils;
13 $bytes =~ y/A-Z[\\]^/a-z{|}~/;
20 if (nickcmp(get_info('version'), '2.4.0') < 0) {
21 @rcolors = (3, 4, 6, 8, 9, 10, 11, 12, 13);
23 @rcolors = (19, 20, 22, 24, 25, 26, 27, 28, 29);
30 $col += ord for split //, $nick;
31 return sprintf "\003%d%s", $rcolors[$col % @rcolors], $nick;
35 'clear' => [ 'COLOR 0' ],
36 'highlight' => [ 'FLASH' => 'COLOR 3' ],
40 my $commands = $gui_commands{$_[0] || 'nope'};
41 die 'Invalid command' unless defined $commands;
42 command "GUI $_" for @$commands;
46 my $cur_cxt = get_context;
47 bless \$cur_cxt, 'Xchat::XPI::Utils::ContextGuard';
51 return unless @_ >= 2;
53 my $new_cxt = (@_ == 1) ? $_[0] : find_context(@_);
54 my $cur_cxt = get_context;
55 if (set_context $new_cxt) {
56 my $guard = bless \$cur_cxt, 'Xchat::XPI::Utils::ContextGuard';
63 sub Xchat::XPI::Utils::ContextGuard::DESTROY {
67 sub called_from_script (&) {
70 my ($package, $filename);
72 my @frame = caller $level;
74 if ($frame[0] !~ /^(?:Xchat|HexChat)::XPI\b/) {
75 ($package, $filename) = @frame[0, 1];
80 if (defined $filename) {
81 my $internal_package = Xchat::Embed::file2pkg($filename);
82 my $mock = sub { $internal_package, $package };
83 no warnings 'redefine';
84 local *Xchat::Embed::find_pkg = $mock;
85 local *HexChat::Embed::find_pkg = $mock;
90 use base qw<Exporter>;
93 our %EXPORT_TAGS = ('funcs' => [ qw<
97 save_context local_context
100 our @EXPORT_OK = map { @$_ } values %EXPORT_TAGS;
101 $EXPORT_TAGS{'all'} = [ @EXPORT_OK ];