diff options
| author | Darkelarious <darkelarious@333networks.com> | 2015-02-09 07:58:06 +0100 |
|---|---|---|
| committer | Darkelarious <darkelarious@333networks.com> | 2015-02-09 07:58:06 +0100 |
| commit | 5057ec47aa9a1702b2483e0a0b3ba325bb0b7abb (patch) | |
| tree | b1a394f64ec7ec2cf69f33bceb54a5b51199c0a4 /lib/MasterServer.pm | |
| parent | 6ac9d390e417b868b6ed79441b8cc6e1b2ebeb13 (diff) | |
| download | MasterServer-Perl-5057ec47aa9a1702b2483e0a0b3ba325bb0b7abb.tar.gz MasterServer-Perl-5057ec47aa9a1702b2483e0a0b3ba325bb0b7abb.zip | |
receive UDP beacons, validate them and store with country indicator
Diffstat (limited to 'lib/MasterServer.pm')
| -rwxr-xr-x | lib/MasterServer.pm | 50 |
1 files changed, 50 insertions, 0 deletions
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; |
