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 my $cur_cxt = get_context;
28 bless \$cur_cxt, 'Xchat::XPI::Utils::ContextGuard';
32 return unless @_ >= 2;
34 my $new_cxt = (@_ == 1) ? $_[0] : find_context(@_);
35 my $cur_cxt = get_context;
36 if (set_context $new_cxt) {
37 my $guard = bless \$cur_cxt, 'Xchat::XPI::Utils::ContextGuard';
44 sub Xchat::XPI::Utils::ContextGuard::DESTROY {
48 sub called_from_script (&) {
51 my ($package, $filename);
53 my @frame = caller $level;
55 if ($frame[0] !~ /^(?:Xchat|HexChat)::XPI\b/) {
56 ($package, $filename) = @frame[0, 1];
61 if (defined $filename) {
62 my $internal_package = Xchat::Embed::file2pkg($filename);
63 my $mock = sub { $internal_package, $package };
64 no warnings 'redefine';
65 local *Xchat::Embed::find_pkg = $mock;
66 local *HexChat::Embed::find_pkg = $mock;
71 use base qw<Exporter>;
74 our %EXPORT_TAGS = ('funcs' => [ qw<
76 save_context local_context
79 our @EXPORT_OK = map { @$_ } values %EXPORT_TAGS;
80 $EXPORT_TAGS{'all'} = [ @EXPORT_OK ];