X-Git-Url: http://git.vpit.fr/?p=perl%2Fscripts%2Fxchat.git;a=blobdiff_plain;f=Xchat%2FXPI.pm;h=0733175382a71dde90c6e0d775e1af8a7d818fa6;hp=1d9236454c1ef9d715d77a50c30ce55654b5aee0;hb=HEAD;hpb=73947ac5d6fffbe5b5ad7f86a9d57d5ada557e6b diff --git a/Xchat/XPI.pm b/Xchat/XPI.pm index 1d92364..0733175 100644 --- a/Xchat/XPI.pm +++ b/Xchat/XPI.pm @@ -7,6 +7,9 @@ use Tie::RefHash; use Xchat; +use lib Xchat::get_info('xchatdir'); +use Xchat::XPI::Utils qw; + 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'; @@ -40,11 +43,11 @@ sub new { $opts{version} = $version; } unless (defined $opts{banner}) { - my $email = $opts{email}; - $email = "<$email>" if defined $email; - my $who = join ', ', grep defined, $opts{author}, $email, $opts{url}; + my $author = defined $opts{author} ? $opts{author} : 'unknown hacker'; + my $email = defined $opts{email} ? "<$opts{email}>" : undef; + my $who = join ', ', grep defined, $email, $opts{url}; $who = " ($who)" if length $who; - $opts{banner} = $opts{desc} . $who; + $opts{banner} = $opts{desc} . " by $author$who"; } my $ph = bless \do { local *PH }, $class; @@ -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}, 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}, 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,