File: Network.pm

package info (click to toggle)
hexchat 3.0.0-0.1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 12,028 kB
  • sloc: ansic: 61,043; xml: 3,988; perl: 1,144; python: 885; cs: 589; cpp: 307; sh: 130; makefile: 25
file content (33 lines) | stat: -rw-r--r-- 762 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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