X-Git-Url: http://git.vpit.fr/?p=perl%2Fscripts%2Fxchat.git;a=blobdiff_plain;f=Xchat%2FXPI.pm;h=ff98ec762b9150f59e1ed50a680eded1469113d5;hp=2c42115dee05bdfac6611f05bf9c298de9629652;hb=bc7fad34cd01ea436368b5e099cede0aa17abab6;hpb=c89e62b2896ac98ebdfac7d77d6dc31e2db3c6a5 diff --git a/Xchat/XPI.pm b/Xchat/XPI.pm index 2c42115..ff98ec7 100644 --- a/Xchat/XPI.pm +++ b/Xchat/XPI.pm @@ -7,13 +7,13 @@ use Tie::RefHash; use Xchat; -our $VERSION = '0.04'; +our $VERSION = '0.05'; use constant { COLOR_TAG => "\00307" }; my @attributes; BEGIN { - @attributes = qw/tag name version desc author email url banner/; + @attributes = qw; } local *PH; @@ -24,18 +24,27 @@ sub new { my %opts = @_; my $caller = (caller 0)[0]; - $opts{tag} ||= ($caller =~ /([^:]*):*$/) ? $1 : 'UNKNOWN'; - $opts{name} ||= $opts{tag}; - $opts{desc} ||= $opts{name}; - $opts{version} ||= do { no strict 'refs'; ${$caller.'::VERSION'} } - || '0.01'; - - my $email = $opts{email}; - $email = "<$email>" if defined $email; - - my $who = join ', ', grep defined, $opts{author}, $email, $opts{url}; - $who = " ($who)" if length $who; - $opts{banner} = $opts{desc} . $who; + unless (defined $opts{tag}) { + $opts{tag} = ($caller =~ /([^:]*):*$/) ? $1 : 'UNKNOWN'; + } + unless (defined $opts{name}) { + $opts{name} = $opts{tag}; + } + unless (defined $opts{desc}) { + $opts{desc} = $opts{name}; + } + unless (defined $opts{version}) { + my $version = do { no strict 'refs'; ${$caller.'::VERSION'} }; + $version = '0.01' unless defined $version; + $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}; + $who = " ($who)" if length $who; + $opts{banner} = $opts{desc} . $who; + } my $ph = bless \do { local *PH }, $class; tie *$ph, $ph, @_; @@ -43,7 +52,7 @@ sub new { *$ph->{$_} = $opts{$_} for @attributes; *$ph->{buf} = ''; - Xchat::register(@opts{qw/name version banner/}, sub { + Xchat::register(@opts{qw}, sub { $ph->flush; if (*$ph->{atexit_id}) { my @callbacks = sort { *$ph->{atexit}{$b} <=> *$ph->{atexit}{$a} } @@ -61,7 +70,8 @@ sub new { } BEGIN { - eval "sub $_ { my \$ph = \$_[0]; *\$ph->{$_} }" for @attributes; + local $@; + eval "sub $_ { my \$ph = \$_[0]; *\$ph->{$_} }; 1" or die $@ for @attributes; } sub print { @@ -125,12 +135,4 @@ sub PRINT { shift->print(@_) } sub PRINTF { shift->printf(@_) } -my $ph = __PACKAGE__->new( - name => 'Extended Xchat Perl Interface', - desc => 'Adds extended support for Perl scripts', - author => 'Vincent Pit (VPIT)', - email => 'perl@profvince.com', - url => 'http://www.profvince.com', -); - 1;