1 package Xchat::XPI::Utils;
12 if (nickcmp(get_info('version'), '2.4.0') < 0) {
13 @rcolors = (3, 4, 6, 8, 9, 10, 11, 12, 13);
15 @rcolors = (19, 20, 22, 24, 25, 26, 27, 28, 29);
22 $col += ord for split //, $nick;
23 return sprintf "\003%d%s", $rcolors[$col % @rcolors], $nick;
27 'clear' => [ 'COLOR 0' ],
28 'highlight' => [ 'FLASH' => 'COLOR 3' ],
32 my $commands = $gui_commands{$_[0] || 'nope'};
33 die 'Invalid command' unless defined $commands;
34 command "GUI $_" for @$commands;
38 my $cur_cxt = get_context;
39 bless \$cur_cxt, 'Xchat::XPI::Utils::ContextGuard';
43 return unless @_ >= 2;
45 my $new_cxt = (@_ == 1) ? $_[0] : find_context(@_);
46 my $cur_cxt = get_context;
47 if (set_context $new_cxt) {
48 my $guard = bless \$cur_cxt, 'Xchat::XPI::Utils::ContextGuard';
55 sub Xchat::XPI::Utils::ContextGuard::DESTROY {
59 sub called_from_script (&) {
62 my ($package, $filename);
64 my @frame = caller $level;
66 if ($frame[0] !~ /^(?:Xchat|HexChat)::XPI\b/) {
67 ($package, $filename) = @frame[0, 1];
72 if (defined $filename) {
73 my $internal_package = Xchat::Embed::file2pkg($filename);
74 my $mock = sub { $internal_package, $package };
75 no warnings 'redefine';
76 local *Xchat::Embed::find_pkg = $mock;
77 local *HexChat::Embed::find_pkg = $mock;
82 use base qw<Exporter>;
85 our %EXPORT_TAGS = ('funcs' => [ qw<
88 save_context local_context
91 our @EXPORT_OK = map { @$_ } values %EXPORT_TAGS;
92 $EXPORT_TAGS{'all'} = [ @EXPORT_OK ];