]> git.vpit.fr Git - perl/scripts/xchat.git/blobdiff - Xchat/XPI.pm
Pretend that the xchat functions in XPI are called from the script
[perl/scripts/xchat.git] / Xchat / XPI.pm
index 6811e63b3bc0355bc355b7841b77eb343aa51f54..0733175382a71dde90c6e0d775e1af8a7d818fa6 100644 (file)
@@ -7,6 +7,9 @@ use Tie::RefHash;
 
 use Xchat;
 
+use lib Xchat::get_info('xchatdir');
+use Xchat::XPI::Utils qw<called_from_script>;
+
 our $VERSION = '0.05';
 
 use constant { COLOR_TAG => "\00307" };
@@ -23,7 +26,7 @@ sub new {
  $class    = ref($class) || $class;
  my %opts  = @_;
 
- my ($caller, $file) = (caller 0)[0, 1];
+ my $caller = (caller 0)[0];
 
  unless (defined $opts{tag}) {
   $opts{tag}     = ($caller =~ /([^:]*):*$/) ? $1 : 'UNKNOWN';
@@ -53,19 +56,17 @@ sub new {
  *$ph->{$_}  = $opts{$_} for @attributes;
  *$ph->{buf} = '';
 
- my $internal_pkg = Xchat::Embed::file2pkg($file);
- no warnings 'redefine';
- local *Xchat::Embed::find_pkg   = sub { $internal_pkg, $caller };
- local *HexChat::Embed::find_pkg = sub { $internal_pkg, $caller };
- Xchat::register(@opts{qw<name version banner>}, sub {
-  $ph->flush;
-  if (*$ph->{atexit_id}) {
-   my @callbacks = sort { *$ph->{atexit}{$b} <=> *$ph->{atexit}{$a} }
-                    keys %{*$ph->{atexit}};
-   $_->($ph) for @callbacks;
-  }
-  undef $ph;
- });
+ called_from_script {
+  Xchat::register(@opts{qw<name version banner>}, sub {
+   $ph->flush;
+   if (*$ph->{atexit_id}) {
+    my @callbacks = sort { *$ph->{atexit}{$b} <=> *$ph->{atexit}{$a} }
+                     keys %{*$ph->{atexit}};
+    $_->($ph) for @callbacks;
+   }
+   undef $ph;
+  })
+ };
  $ph->add_atexit($opts{unload}) if $opts{unload};
 
  $ph->print("\002", $ph->name, ' v', $ph->version,