From 5057ec47aa9a1702b2483e0a0b3ba325bb0b7abb Mon Sep 17 00:00:00 2001 From: Darkelarious Date: Mon, 9 Feb 2015 07:58:06 +0100 Subject: receive UDP beacons, validate them and store with country indicator --- lib/MasterServer.pm | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100755 lib/MasterServer.pm (limited to 'lib/MasterServer.pm') diff --git a/lib/MasterServer.pm b/lib/MasterServer.pm new file mode 100755 index 0000000..c0bd914 --- /dev/null +++ b/lib/MasterServer.pm @@ -0,0 +1,50 @@ + +package MasterServer; + +use strict; +use warnings; + +our $OBJ = bless {}, 'MasterServer::Object'; + +# Load modules, recursively +# All submodules should be under the same directory in @INC +# Greets to Yorhel for this one. +sub load_recursive { + my $rec; + $rec = sub { + my($d, $f, $m) = @_; + for my $s (glob "$d/$f/*") { + $OBJ->_load_module("${m}::$1") if -f $s && $s =~ /([^\/]+)\.pm$/; + $rec->($d, "$f/$1", "${m}::$1") if -d $s && $s =~ /([^\/]+)$/; + } + }; + for my $m (@_) { + (my $f = $m) =~ s/::/\//g; + my $d = (grep +(-d "$_/$f" or -s "$_/$f.pm"), @INC)[0]; + $OBJ->_load_module($m) if -s "$d/$f.pm"; + $rec->($d, $f, $m) if -d "$d/$f"; + } +} + +# Load modules +sub load { + $OBJ->_load_module($_) for (@_); +} + +# run our master server +sub run { + $OBJ->main(); +} + +# The namespace which inherits all functions to be available in the global +# object. +package MasterServer::Object; + +# load modules +sub _load_module { + my($self, $module) = @_; + die $@ if !eval "use $module; 1"; +} + + +1; -- cgit v1.2.3