summary refs log tree commit diff stats
path: root/plugins/perl/lib/HexChat/List/Network/AutoJoin.pm
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/perl/lib/HexChat/List/Network/AutoJoin.pm')
-rw-r--r--plugins/perl/lib/HexChat/List/Network/AutoJoin.pm80
1 files changed, 80 insertions, 0 deletions
diff --git a/plugins/perl/lib/HexChat/List/Network/AutoJoin.pm b/plugins/perl/lib/HexChat/List/Network/AutoJoin.pm
new file mode 100644
index 00000000..cc51af25
--- /dev/null
+++ b/plugins/perl/lib/HexChat/List/Network/AutoJoin.pm
@@ -0,0 +1,80 @@
+package HexChat::List::Network::AutoJoin;
+use strict;
+use warnings;
+
+use overload
+#	'%{}' => \&as_hash,
+#	'@{}' => \&as_array,
+	'""'   => 'as_string',
+	'0+'   => 'as_bool';
+
+sub new {
+	my $class = shift;
+
+	my @autojoins;
+
+	return bless \@autojoins, $class;
+}
+
+sub add {
+	my $self = shift;
+
+	my $line = shift;
+
+	my ( $channel, $key ) = split /,/, $line, 2;
+	$key = $key || '';
+
+	push @$self, {
+		channel => $channel,
+		key     => $key,
+		};
+}
+
+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