Ubic
view release on metacpan - search on metacpan
view release on metacpan or search on metacpan
lib/Ubic/Cmd.pm view on Meta::CPAN
package Ubic::Cmd;
$Ubic::Cmd::VERSION = '1.60';
use strict;
use warnings;
# ABSTRACT: ubic methods with pretty printing.
use Params::Validate qw(:all);
use Scalar::Util qw(blessed);
use List::MoreUtils qw(any);
use List::Util qw(max);
use Try::Tiny;
use Ubic;
use Ubic::Result qw(result);
use Ubic::Cmd::Results;
sub new {
my $class = shift;
my $self = validate(@_, {});
return bless $self => $class;
}
our $SINGLETON;
sub _obj {
my ($param) = validate_pos(@_, 1);
if (blessed($param)) {
return $param;
}
if ($param eq 'Ubic::Cmd') {
# method called as a class method => singleton
$SINGLETON ||= Ubic::Cmd->new();
return $SINGLETON;
}
die "Unknown argument '$param'";
}
sub _any_method {
my $self = shift;
my $params = validate(@_, {
service => 1,
results => 0,
action => 1, # Starting/Stopping/...
method => 1,
enabled_only => 0,
});
my ($service, $results, $action, $method, $enabled_only) = @$params{qw/ service results action method enabled_only /};
$results ||= Ubic::Cmd::Results->new;
$self->traverse($service, sub {
my $service = shift;
my $name = $service->full_name;
if ($enabled_only and not Ubic->is_enabled($name)) {
print "$name is down\n";
$results->add(result('down'));
return;
}
print "$action $name... ";
my $result = eval { Ubic->$method($name) };
$result ||= result($@);
$results->print($result, $@ ? 'bad' : ());
});
return $results;
}
sub start {
my $self = _obj(shift);
return $self->_any_method({
service => shift,
results => shift,
action => 'Starting',
method => 'start',
});
}
sub stop {
my $self = _obj(shift);
return $self->_any_method({
view all matches for this distributionview release on metacpan - search on metacpan
( run in 1.264 second using v1.00-cache-2.02-grep-82fe00e-cpan-2c419f77a38b )