diff --git a/lib/L.pm b/lib/L.pm new file mode 100644 index 00000000..95ab1761 --- /dev/null +++ b/lib/L.pm @@ -0,0 +1,14 @@ +package L; + +# Intended to be used from the command line to save a bunch of typing. + +# This derives off Lacuna, thus can be used like Lacuna: +# perl -ML -E 'say L->cache->get(...)' + +use parent 'Lacuna'; +use LD; +use LR; + +use L; + +1; diff --git a/lib/LD.pm b/lib/LD.pm new file mode 100644 index 00000000..1e97fd2a --- /dev/null +++ b/lib/LD.pm @@ -0,0 +1,31 @@ +package LD; + +# Intended to be used from the command line to save a bunch of typing. + +# This "derives" off Lacuna::DB, and is simply a shortcut for +# typing Lacuna->db: +# perl -ML -E 'say LD->empire(2)->name' +# perl -ML -MData::Dump -e 'dd(Lacuna::RPC::Empire->new->view_profile(LD->empire(2))' + +use L; + +our $AUTOLOAD; +sub AUTOLOAD +{ + my $self = shift; + my $func = $AUTOLOAD; + $func =~ s/^.*:://; + + my $db = L->db; + + if (my $code = $db->can($func)) + { + return $db->$code(@_); + } + else + { + die "Lacuna::DB cannot $func\n"; + } +} + +1; diff --git a/lib/LR.pm b/lib/LR.pm new file mode 100644 index 00000000..51c64fe7 --- /dev/null +++ b/lib/LR.pm @@ -0,0 +1,22 @@ +package LR; + +# Intended to be used from the command line to save a bunch of typing. + +# This "derives" off Lacuna::RPC, and is simply a shortcut for +# Lacuna::RPC::...->new: +# perl -ML -MData::Dump -e 'dd(LR->Empire->view_profile(LD->empire(2))' + +our $AUTOLOAD; +sub AUTOLOAD +{ + my $self = shift; + my $ns = $AUTOLOAD; + $ns =~ s/^.*:://; + + require "Lacuna/RPC/$ns.pm"; + $ns = "Lacuna::RPC::$ns"; + + $ns->new(); +} + +1; diff --git a/lib/Lacuna/DB.pm b/lib/Lacuna/DB.pm index 3dff35ff..a851330f 100644 --- a/lib/Lacuna/DB.pm +++ b/lib/Lacuna/DB.pm @@ -48,9 +48,19 @@ sub empire { my $empires = $self->resultset('Empire'); my $where = $self->_where(name => $id); - $empires->find($where)->single; + $empires->find($where); } +sub empires { + my ($self, $id) = @_; + + my $empires = $self->resultset('Empire'); + my $where = $self->_where(name => $id); + + $empires->search($where); +} + + sub body { my ($self, $id) = @_; @@ -60,11 +70,28 @@ sub body { $bodies->find($where); } +sub bodies { + my ($self, $id) = @_; + + my $bodies = $self->resultset('Map::Body'); + my $where = $self->_where(name => $id); + + $bodies->search($where); +} + # similarly, a lot of typing can be saved with Lacuna->db->building($id) sub building { my ($self, $building_id) = @_; - my $building = $self->resultset('Building')->find($building_id); + $self->resultset('Building')->find($building_id); +} + + +sub buildings { + my ($self, $id) = @_; + my $where = $self->_where(name => $id); + $self->resultset('Building')->search($where); } + no Moose; __PACKAGE__->meta->make_immutable; diff --git a/lib/Lacuna/RPC/Empire.pm b/lib/Lacuna/RPC/Empire.pm index 9e6239b1..9ffe3fba 100644 --- a/lib/Lacuna/RPC/Empire.pm +++ b/lib/Lacuna/RPC/Empire.pm @@ -198,7 +198,7 @@ sub change_password { ->eq($password2); my $empire = $self->get_empire_by_session($session_id); - if ($empire->current_session->is_sitter) { + if ($empire->has_current_session && $empire->current_session->is_sitter) { confess [1015, 'Sitters cannot modify the main account password.']; } @@ -387,7 +387,7 @@ sub get_status { sub view_profile { my ($self, $session_id) = @_; my $empire = $self->get_empire_by_session($session_id); - if ($empire->current_session->is_sitter) { + if ($empire->has_current_session && $empire->current_session->is_sitter) { confess [1015, 'Sitters cannot modify preferences.']; } my $medals = $empire->medals; @@ -439,7 +439,7 @@ sub edit_profile { my $empire = $self->get_empire_by_session($session_id); # preferences - if ($empire->current_session->is_sitter) { + if ($empire->has_current_session && $empire->current_session->is_sitter) { confess [1015, 'Sitters cannot modify preferences.']; } if (exists $profile->{description}) {