From: Vincent Pit Date: Sat, 10 Mar 2012 10:33:03 +0000 (+0100) Subject: Xchat::XPI->new options handling overhaul X-Git-Url: http://git.vpit.fr/?p=perl%2Fscripts%2Fxchat.git;a=commitdiff_plain;h=80f827633d7173e4388bfce83f6bb304f37cecab Xchat::XPI->new options handling overhaul --- diff --git a/Xchat/XPI.pm b/Xchat/XPI.pm index 6927d83..7481f5c 100644 --- a/Xchat/XPI.pm +++ b/Xchat/XPI.pm @@ -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, @_;