Acrux

 view release on metacpan or  search on metacpan

lib/Acrux/Digest.pm  view on Meta::CPAN


=head1 ATTRIBUTES

This class implements the following attributes

=head2 data

    my $data = $provider->data;
    $provider = $provider->data({foo => 'bar'});

Data structure to be processed

=head1 METHODS

This class implements the following methods

=head2 add

    $provider->add("data", "and another data", ...);

Add data to digest calculate.

lib/Acrux/FilePid.pm  view on Meta::CPAN

    my $fp = Acrux::FilePid->new (
        file => '/some/file.pid',
        auto => 1,
    );
    die "Already running" if $fp->running;
    # . . .

=head1 DESCRIPTION

This software manages a pid file for you. It will create a pid file,
query the process within to discover if it's still running, and remove
the pid file.

=head2 new

    my $fp = Acrux::FilePid->new;

    my $fp = Acrux::FilePid->new(
        file => '/var/run/daemon.pid',
    );

lib/Acrux/FilePid.pm  view on Meta::CPAN


Removes the pid file from disk. Returns true on success, false on
failure.

=head2 running

    my $pid = $fp->running;
    die "Service already running: $pid" if $pid;

Checks to see if the pricess identified in the pid file is still
running. If the process is still running, the pid is returned. Otherwise
C<undef> is returned.

=head2 save

    $fp->save;

Writes the pid file to disk, inserting the pid inside the file.
On success, the object is returned. On failure, C<undef> is
returned.

lib/Acrux/Pointer.pm  view on Meta::CPAN


=head1 ATTRIBUTES

This class implements the following attributes

=head2 data

    my $data = $pointer->data;
    $pointer = $pointer->data({foo => 'bar'});

Data structure to be processed

=head1 METHODS

This class implements the following methods

=head2 contains

    my $bool = $pointer->contains('/foo/1');

Check if L</"data"> contains a value that can be identified with the given pointer

lib/Acrux/Util.pm  view on Meta::CPAN


=item mode

This numeric argument sets the default mode of opening files to write.
By default this argument to C<(O_WRONLY | O_CREAT)>.
Please DO NOT set this argument unless really necessary!

=item perms

This argument sets the permissions of newly-created files.
This value is modified by your process's umask and defaults to 0666 (same as sysopen)

=back

See also L</slurp> to reading data from file

=head2 spurt

See L</spew>

=head2 strf

lib/Acrux/Util.pm  view on Meta::CPAN

}

# Text utils
sub trim {
    my $val = shift;
    return unless defined $val;
    $val =~ s|^\s+||s; # trim left
    $val =~ s|\s+$||s; # trim right
    return $val;
}
sub dformat { # Simple templating processor
    my $f = shift;
    my $d = @_ ? @_ > 1 ? {@_} : {%{$_[0]}} : {};
    $f =~ s/\[([A-Z0-9_\-.]+?)\]/(defined($d->{$1}) ? $d->{$1} : "[$1]")/eg;
    return $f;
}
sub strf { # Yet another simple templating processor
    my $s = shift // '';
    my $h = @_ ? @_ > 1 ? {@_} : {%{$_[0]}} : {};
    return '' unless length $s;
    $h->{'%'} //= '%'; # by default '%' eq '%''

    $s =~ s/
            (?:
              %\{(\w+)\}       # short name like %{name}
              |
              %([%a-zA-Z])     # single character specifier like %d

t/05-filepid.t  view on Meta::CPAN

#
#########################################################################
use strict;
use Test::More;

use_ok qw/Acrux::FilePid/;

# Regular mode
{
    my $fp = Acrux::FilePid->new(file => "test05.pid");
    is $fp->pid, $$, "$$ current process by default";
    ok $fp->save, "$$ writing file";
    is $fp->running, $$, "$$ we are running";
    ok $fp->remove, "$$ deleted file";
    #note explain $fp;
}

# Autoremove mode
{
    my $fp = Acrux::FilePid->new(file => "test05.tmp", autoremove => 1);
    ok $fp->save, "$$ writing file";

t/05-filepid.t  view on Meta::CPAN

}

# Fork mode
my $file = 'child05.tmp';
unlink $file if -e $file;
if (my $child = fork) { # Parent PID
    sleep 1;
    my $p = Acrux::FilePid->new(file => $file, autoremove => 1);
    note sprintf "Parent PID: %s; Parent Owner: %s", $p->pid, $p->owner;
    $p->save unless $p->running;
    ok $p->running, 'child process is running';
    #note explain $p;
    waitpid $child, 0;
    done_testing;
} else { # child process
    my $p = Acrux::FilePid->new(file => $file, autoremove => 1); # hope for the best
    unless ($p->running) {
       $p->save;
       note sprintf "Start child process (Child PID: %s; Child Owner: %s)", $p->pid, $p->owner;
       sleep 3;
       note sprintf "Finish child process (Child PID: %s; Child Owner: %s)", $p->pid, $p->owner;
    }
    #note 'parent is running' if $p->running;
}

__END__

prove -lv t/05-filepid.t



( run in 0.410 second using v1.01-cache-2.11-cpan-8d75d55dd25 )