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" };
my @attributes;
BEGIN {
- @attributes = qw/tag name version desc author email url banner/;
+ @attributes = qw<tag name version desc author email url banner>;
}
local *PH;
my %opts = @_;
my $caller = (caller 0)[0];
+
unless (defined $opts{tag}) {
$opts{tag} = ($caller =~ /([^:]*):*$/) ? $1 : 'UNKNOWN';
}
$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;
*$ph->{$_} = $opts{$_} for @attributes;
*$ph->{buf} = '';
- 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,