| 1 | package HTTP::Balancer::Actor; | ||
| 2 | use Modern::Perl; | ||
| 3 | use Moose; | ||
| 4 | use Path::Tiny; | ||
| 5 | |||
| 6 | with qw(HTTP::Balancer::Role); | ||
| 7 | |||
| 8 | use Text::Xslate; | ||
| 9 | |||
| 10 | our @PATH = qw( | ||
| 11 | /usr/local/bin | ||
| 12 | /usr/local/sbin | ||
| 13 | /usr/bin | ||
| 14 | /usr/sbin | ||
| 15 | ); | ||
| 16 | |||
| 17 | sub start { | ||
| 18 | my $class = shift; | ||
| 19 | die "you do not implement the start() for $class"; | ||
| 20 | } | ||
| 21 | |||
| 22 | sub stop { | ||
| 23 | my $class = shift; | ||
| 24 | die "you do not implement the stop() for $class"; | ||
| 25 | } | ||
| 26 | |||
| 27 | sub kill { | ||
| 28 | my ($self, $pid) = @_; | ||
| 29 | if (kill 0, $pid) { | ||
| 30 | kill 15, $pid; | ||
| 31 | } else { | ||
| 32 | warn "could not kill $pid"; | ||
| 33 | } | ||
| 34 | } | ||
| 35 | |||
| 36 | sub executable { | ||
| 37 | my $class = ref($_[0]) ? ref(shift) : shift; | ||
| 38 | my $name = do { | ||
| 39 | no strict "refs"; | ||
| 40 | ${ $class . "::NAME" } or die $class . "::NAME not defined yet"; | ||
| 41 | }; | ||
| 42 | for (@PATH) { | ||
| 43 | return path($_)->child($name)->stringify if path($_)->child($name)->exists; | ||
| 44 | } | ||
| 45 | } | ||
| 46 | |||
| 47 | sub template { | ||
| 48 | my ($self, ) = @_; | ||
| 49 | state $result; | ||
| 50 | no strict "refs"; | ||
| 51 | local $/ = undef; | ||
| 52 | $result //= readline *{ref($self) . "::DATA"}; | ||
| 53 | } | ||
| 54 | |||
| 55 | sub render { | ||
| 56 | my ($self, %args) = @_; | ||
| 57 | Text::Xslate->new->render_string($self->template, \%args); | ||
| 58 | } | ||
| 59 | |||
| 60 | 1; | ||
| 61 | __END__ |