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 return undef unless defined $new_cxt;
55 my $cur_cxt = get_context;
56 my $guard = bless \$cur_cxt, 'Xchat::XPI::Utils::ContextGuard';
57 if (set_context $new_cxt) {
64 sub Xchat::XPI::Utils::ContextGuard::DESTROY {
68 sub called_from_script (&) {
71 my ($package, $filename);
73 my @frame = caller $level;
75 if ($frame[0] !~ /^(?:Xchat|HexChat)::XPI\b/) {
76 ($package, $filename) = @frame[0, 1];
81 if (defined $filename) {
82 my $internal_package = Xchat::Embed::file2pkg($filename);
83 my $mock = sub { $internal_package, $package };
84 no warnings 'redefine';
85 local *Xchat::Embed::find_pkg = $mock;
86 local *HexChat::Embed::find_pkg = $mock;
91 use base qw<Exporter>;
94 our %EXPORT_TAGS = ('funcs' => [ qw<
98 save_context local_context
101 our @EXPORT_OK = map { @$_ } values %EXPORT_TAGS;
102 $EXPORT_TAGS{'all'} = [ @EXPORT_OK ];