diff options
author | berkeviktor@aol.com <berkeviktor@aol.com> | 2011-02-24 04:14:30 +0100 |
---|---|---|
committer | berkeviktor@aol.com <berkeviktor@aol.com> | 2011-02-24 04:14:30 +0100 |
commit | 4a6ceffb98a0b785494f680d3776c4bfc4052f9e (patch) | |
tree | 850703c1c841ccd99f58d0b06084615aaebe782c /plugins/perl/lib/Xchat/List/Network/AutoJoin.pm | |
parent | f16af8be941b596dedac3bf4e371ee2d21f4b598 (diff) |
add xchat r1489
Diffstat (limited to 'plugins/perl/lib/Xchat/List/Network/AutoJoin.pm')
-rw-r--r-- | plugins/perl/lib/Xchat/List/Network/AutoJoin.pm | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/plugins/perl/lib/Xchat/List/Network/AutoJoin.pm b/plugins/perl/lib/Xchat/List/Network/AutoJoin.pm new file mode 100644 index 00000000..16036a9d --- /dev/null +++ b/plugins/perl/lib/Xchat/List/Network/AutoJoin.pm @@ -0,0 +1,82 @@ +package Xchat::List::Network::AutoJoin; +use strict; +use warnings; + +use overload +# '%{}' => \&as_hash, +# '@{}' => \&as_array, + '""' => 'as_string', + '0+' => 'as_bool'; + +sub new { + my $class = shift; + my $line = shift; + + my @autojoins; + + if ( $line ) { + my ( $channels, $keys ) = split / /, $line, 2; + my @channels = split /,/, $channels; + my @keys = split /,/, ($keys || ''); + + for my $channel ( @channels ) { + my $key = shift @keys; + $key = '' unless defined $key; + + push @autojoins, { + channel => $channel, + key => $key, + }; + } + } + return bless \@autojoins, $class; +} + +sub channels { + my $self = shift; + + if( wantarray ) { + return map { $_->{channel} } @$self; + } else { + return scalar @$self; + } +} + +sub keys { + my $self = shift; + return map { $_->{key} } @$self ; + +} + +sub pairs { + my $self = shift; + + my @channels = $self->channels; + my @keys = $self->keys; + + my @pairs = map { $_ => shift @keys } @channels; +} + +sub as_hash { + my $self = shift; + return +{ $self->pairs }; +} + +sub as_string { + my $self = shift; + return join " ", + join( ",", $self->channels ), + join( ",", $self->keys ); +} + +sub as_array { + my $self = shift; + return [ map { \%$_ } @$self ]; +} + +sub as_bool { + my $self = shift; + return $self->channels ? 1 : ""; +} + +1 |