summary refs log tree commit diff stats
path: root/plugins/perl/lib/HexChat/List/Network.pm
diff options
context:
space:
mode:
authorFarow <farow_spam@lavabit.com>2013-10-02 17:47:56 +0300
committerEustachy Kapusta <Eustachy.kapusta@gmail.com>2013-10-07 22:58:38 +0200
commit075cc61c942998b7fdfeabfde10490ef233f88cd (patch)
tree00d3c95ac10ab8b5d3ff325d977860545e9ad661 /plugins/perl/lib/HexChat/List/Network.pm
parentaafbb6374b903d0c8ec5364f4cb3f2065cc7d31e (diff)
Rebrand Perl plugin to HexChat,
Add /pl and plugin_pref

Add help messages
Diffstat (limited to 'plugins/perl/lib/HexChat/List/Network.pm')
-rw-r--r--plugins/perl/lib/HexChat/List/Network.pm33
1 files changed, 33 insertions, 0 deletions
diff --git a/plugins/perl/lib/HexChat/List/Network.pm b/plugins/perl/lib/HexChat/List/Network.pm
new file mode 100644
index 00000000..64b3d14c
--- /dev/null
+++ b/plugins/perl/lib/HexChat/List/Network.pm
@@ -0,0 +1,33 @@
+package HexChat::List::Network;
+use strict;
+use warnings;
+use Storable qw(dclone);
+my $last_modified;
+my @servers;
+
+sub get {
+	my $server_file = HexChat::get_info( "configdir" ) . "/servlist.conf";
+
+	# recreate the list only if the server list file has changed
+	if( -f $server_file && 
+			(!defined $last_modified || $last_modified != -M $server_file ) ) {
+		$last_modified = -M _;
+
+		@servers = ();
+		if( open my $fh, "<", $server_file ) {
+			local $/ = "\n\n";
+			while( my $record = <$fh> ) {
+				chomp $record;
+				next if $record =~ /^v=/; # skip the version line
+				push @servers, HexChat::List::Network::Entry::parse( $record );
+			}
+		} else {
+			warn "Unable to open '$server_file': $!";
+		}
+	}
+
+	my $clone = dclone( \@servers );
+	return @$clone;
+}
+
+1