view release on metacpan or search on metacpan
lib/Ubic.pm view on Meta::CPAN
my $self = {};
$self->{data_dir} = Ubic::Settings->data_dir;
$self->{service_dir} = Ubic::Settings->service_dir;
$self->{status_dir} = "$self->{data_dir}/status";
$self->{lock_dir} = "$self->{data_dir}/lock";
$self->{tmp_dir} = "$self->{data_dir}/tmp";
$self->{service_cache} = {};
return bless $self => $class;
}
sub start($$) {
my $self = _obj(shift);
my ($name) = validate_pos(@_, $validate_service);
my $lock = $self->lock($name);
$self->enable($name);
my $result = $self->do_cmd($name, 'start');
$self->set_cached_status($name, $result);
lib/Ubic/Cmd.pm view on Meta::CPAN
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') {
lib/Ubic/Credentials/OS/MacOSX.pm view on Meta::CPAN
$self->{group} = $group[0] if @group;
}
else {
$self->{real_user_id} = $<;
$self->{effective_user_id} = $>;
($self->{real_group_id}) = $( =~ /^(\d+)/;
($self->{effective_group_id}) = $) =~ /^(\d+)/;
# TODO - derive user from real_user_id when user is not specified (or from effective_user_id?!)
}
return bless $self => $class;
}
sub user {
my $self = shift;
unless (defined $self->{user}) {
$self->{user} = getpwuid($>);
}
return $self->{user};
}
lib/Ubic/Credentials/OS/POSIX.pm view on Meta::CPAN
$self->{group} = [ @group ] if @group;
}
else {
$self->{real_user_id} = $<;
$self->{effective_user_id} = $>;
$self->{real_group_id} = [ split / /, $( ];
$self->{effective_group_id} = [ split / /, $) ];
# TODO - derive user from real_user_id when user is not specified (or from effective_user_id?!)
}
return bless $self => $class;
}
sub user {
my $self = shift;
unless (defined $self->{user}) {
my $user = getpwuid($>);
unless (defined $user) {
die "failed to get user name by uid $>";
}
$self->{user} = $user;
lib/Ubic/Credentials/OS/Windows.pm view on Meta::CPAN
use strict;
use warnings;
# ABSTRACT: dummy credentials module
use parent qw(Ubic::Credentials);
sub new {
my $class = shift;
return bless {} => $class;
}
sub set_effective {}
sub reset_effective {}
sub eq { 1 }
sub set {}
1;
__END__
lib/Ubic/Daemon/PidState.pm view on Meta::CPAN
use Ubic::AtomicFile;
use overload '""' => sub {
my $self = shift;
return $self->{dir};
};
sub new {
my $class = shift;
my ($dir) = validate_pos(@_, { type => SCALAR });
return bless { dir => $dir } => $class;
}
sub is_empty {
my ($self) = validate_pos(@_, 1);
my $dir = $self->{dir};
return if not -d $dir and -s $dir; # old-style pidfile
return if -d $dir and -s "$dir/pid"; # non-empty new-style pidfile
return 1;
lib/Ubic/Daemon/Status.pm view on Meta::CPAN
use Params::Validate;
sub new {
my $class = shift;
my $params = validate(@_, {
pid => 1,
guardian_pid => 1,
});
return bless $params => $class;
}
sub pid {
my $self = shift;
validate_pos(@_);
return $self->{pid};
}
sub guardian_pid {
my $self = shift;
lib/Ubic/Multiservice/Dir.pm view on Meta::CPAN
sub new {
my $class = shift;
my ($dir, @options) = validate_pos(@_, 1, 0);
my $options = {};
if (@options) {
$options = validate(@options, {
protected => 0,
});
}
return bless { service_dir => $dir, %$options } => $class;
}
sub has_simple_service {
my $self = shift;
my ($name) = validate_pos(@_, {type => SCALAR, regex => qr/^[\w.-]+$/});
if ($self->_name2file($name)) {
return 1;
}
else {
return;
lib/Ubic/Multiservice/Simple.pm view on Meta::CPAN
type => HASHREF,
callbacks => {
'values are services' => sub {
for (values %{shift()}) {
return unless blessed($_) and $_->isa('Ubic::Service')
}
return 1;
},
}
});
return bless { services => $params } => $class;
}
sub has_simple_service($$) {
my ($self, $name) = @_;
return exists $self->{services}{$name};
}
sub simple_service($$) {
my ($self, $name) = @_;
return $self->{services}{$name};
lib/Ubic/Persistent.pm view on Meta::CPAN
return _load($fname);
}
sub new {
my ($class, $fname) = @_;
my $lock = lockf("$fname.lock", { blocking => 1 });
my $self = {};
$self = _load($fname) if -e $fname;
bless $self => $class;
$meta->{$self} = { lock => $lock, fname => $fname };
return $self;
}
sub commit {
my $self = shift;
my $fname = $meta->{$self}{fname};
Ubic::AtomicFile::store(objToJson({ %$self }) => $fname);
}
lib/Ubic/Result/Class.pm view on Meta::CPAN
__PACKAGE__->mk_accessors(qw/ type msg /);
sub new {
my $class = shift;
my $self = validate(@_, {
type => { type => SCALAR, optional => 1 },
msg => { optional => 1 },
cached => { optional => 1 },
});
$self->{type} ||= 'unknown';
return bless $self => $class;
}
sub status {
my $self = shift;
croak 'status() is read-only method' if @_;
if (grep { $_ eq $self->{type} } ('running', 'already running', 'started', 'already started', 'restarted', 'reloaded', 'stopping')) {
return 'running';
}
elsif (grep { $_ eq $self->{type} } ('not running', 'stopped', 'starting')) {
return 'not running';
lib/Ubic/Service/Common.pm view on Meta::CPAN
custom_commands => { type => HASHREF, default => {} },
user => { type => SCALAR, optional => 1 },
group => { type => SCALAR | ARRAYREF, optional => 1 },
timeout_options => { type => HASHREF, default => {} },
});
if ($params->{custom_commands}) {
for (keys %{$params->{custom_commands}}) {
ref($params->{custom_commands}{$_}) eq 'CODE' or croak "Callback expected at custom command $_";
}
}
my $self = bless {%$params} => $class;
return $self;
}
sub port {
my $self = shift;
return $self->{port};
}
sub status_impl {
my $self = shift;
lib/Ubic/Service/SimpleDaemon.pm view on Meta::CPAN
eval "require BSD::Resource";
if ($@) {
die "BSD::Resource is not installed";
}
if (BSD::Resource->VERSION < 1.29) {
# 1.29 supports string names for resources
die "BSD::Resource >= 1.29 required";
}
}
return bless {%$params} => $class;
}
sub pidfile {
my ($self) = @_;
return $self->{pidfile} if exists($self->{pidfile});
my $name = $self->full_name or die "Can't start nameless SimpleDaemon";
return _pid_dir."/$name";
}
sub start_impl {
lib/Ubic/ServiceLoader/Ext/ini.pm view on Meta::CPAN
use strict;
use warnings;
use parent qw( Ubic::ServiceLoader::Base );
use Config::Tiny;
sub new {
my $class = shift;
return bless {} => $class;
}
sub load {
my $self = shift;
my ($file) = @_;
my $config = Config::Tiny->read($file);
unless ($config) {
die Config::Tiny->errstr;
}
lib/Ubic/ServiceLoader/Ext/json.pm view on Meta::CPAN
{
# support the compatibility with JSON.pm v1 just because we can
# see also: Ubic::Persistent
no strict;
no warnings;
sub jsonToObj; *jsonToObj = (*{JSON::from_json}{CODE}) ? \&JSON::from_json : \&JSON::jsonToObj;
}
sub new {
my $class = shift;
return bless {} => $class;
}
sub load {
my $self = shift;
my ($file) = @_;
open my $fh, '<', $file or die "Can't open $file: $!";
my $content = do { local $/; <$fh> };
close $fh or die "Can't close $file: $!";
lib/Ubic/SingletonLock.pm view on Meta::CPAN
our %LOCKS;
sub new {
my ($class, $file, $options) = validate_pos(@_, 1, 1, 0);
if ($LOCKS{$file}) {
return $LOCKS{$file};
}
my $lock = lockf($file, $options);
my $self = bless { file => $file, lock => $lock } => $class;
$LOCKS{$file} = $self;
weaken $LOCKS{$file};
return $self;
}
sub DESTROY {
my $self = shift;
local $@;
delete $LOCKS{ $self->{file} };
lib/Ubic/UA.pm view on Meta::CPAN
use strict;
use warnings;
use IO::Socket;
sub new {
my $class = shift;
my %arg = @_;
my $self = {};
$self->{timeout} = $arg{timeout} || 10;
return bless $self => $class;
}
sub get {
my $self = shift;
my ($url) = @_;
unless ($url) {
return { error => 'Url not specified' };
}
lib/Ubic/Watchdog.pm view on Meta::CPAN
for my $arg (@{ $options->{glob_filter} }) {
$arg =~ /^[*\w.-]+$/ or die "Invalid argument '$arg', expected service name or shell-style glob";
$arg =~ s/\./\\./g;
$arg =~ s/\*/.*/g;
push @filter, qr/^$arg$/;
}
}
$options->{filter} = \@filter if @filter;
delete $options->{glob_filter};
my $self = bless $options => $class;
my @services = $self->load_services(Ubic->root_service);
$self->check_all(@services);
}
sub match($$) {
my ($name, $filter) = @_;
do {
return 1 if $name =~ $filter;
} while ($name =~ s/\.[^.]+$//);
t/Utils/IgnoreWarnGuard.pm view on Meta::CPAN
my $prev_sig = $SIG{__WARN__};
$SIG{__WARN__} = sub {
return if $_[0] =~ $regex;
if (ref $prev_sig and ref $prev_sig eq 'CODE') {
$prev_sig->(@_);
}
else {
warn @_;
}
};
return bless { prev_sig => $prev_sig } => $class;
}
sub DESTROY {
my $self = shift;
$SIG{__WARN__} = $self->{prev_sig} if $self->{prev_sig};
delete $ENV{IGNORE_WARN};
}
1;
view all matches for this distributionview release on metacpan - search on metacpan