2013-10-02 10:47:56 -04:00
|
|
|
package HexChat::List::Network;
|
2011-02-23 22:14:30 -05:00
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
use Storable qw(dclone);
|
|
|
|
my $last_modified;
|
|
|
|
my @servers;
|
|
|
|
|
|
|
|
sub get {
|
2013-10-02 10:47:56 -04:00
|
|
|
my $server_file = HexChat::get_info( "configdir" ) . "/servlist.conf";
|
2011-02-23 22:14:30 -05:00
|
|
|
|
|
|
|
# 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 _;
|
|
|
|
|
2011-02-28 13:21:36 -05:00
|
|
|
@servers = ();
|
2011-02-23 22:14:30 -05:00
|
|
|
if( open my $fh, "<", $server_file ) {
|
|
|
|
local $/ = "\n\n";
|
|
|
|
while( my $record = <$fh> ) {
|
|
|
|
chomp $record;
|
|
|
|
next if $record =~ /^v=/; # skip the version line
|
2013-10-02 10:47:56 -04:00
|
|
|
push @servers, HexChat::List::Network::Entry::parse( $record );
|
2011-02-23 22:14:30 -05:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
warn "Unable to open '$server_file': $!";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
my $clone = dclone( \@servers );
|
|
|
|
return @$clone;
|
|
|
|
}
|
|
|
|
|
|
|
|
1
|