Unicorn-Manager

 view release on metacpan or  search on metacpan

lib/Unicorn/Manager/CLI/Proc.pm  view on Meta::CPAN

                    $i++;
                }
            }
        }
    }

    return $self->ptable($tree) ? 1 : 0;
}

1;

package Unicorn::Manager::CLI::Proc;

use Moo;
use JSON;
use strict;
use warnings;
use autodie;
use 5.010;

has process_table => ( is => 'rw', );

sub BUILD {
    my $self = shift;
    $self->process_table( Unicorn::Manager::CLI::Proc::Table->new );
}

sub refresh {
    my $self = shift;
    $self->process_table->refresh;
}

sub as_json {
    my $self = shift;

    my $json = JSON->new->utf8(1);

    return $json->encode( { $self->as_hash } );
}

sub as_hash {
    my $self      = shift;
    my $with_uids = shift;

    if ($with_uids) {
        return %{ $self->process_table->ptable };
    }
    else {
        return %{ $self->_replace_uid_with_name };
    }
}

sub _replace_uid_with_name {
    my $self = shift;

    my %user_table = %{ $self->process_table->ptable };

    my @users = keys %user_table;

    for (@users) {
        my $username = getpwuid $_;
        $user_table{$username} = $user_table{$_};
        delete $user_table{$_};
    }

    return {%user_table};
}

1;

__END__

=head1 NAME

Unicorn::Manager::CLI::Proc - Process table used by Unicorn::Manager

=head1 VERSION

Version 0.006009

=head1 SYNOPSIS

The Unicorn::Manager::CLI::Proc Module provides a table of unicorn processes.
Master/worker states are correctly represented.
The modules utilizes /proc and thus only works on Linux systems.

=head1 ATTRIBUTES/CONSTRUCTION

=head2 Construction

    my $uniman_proc = Unicorn::Manager::CLI::Proc->new;

=head2 process_table

Get the process table.

=head2 refresh

Refreshes the process table.

    $uniman_proc->refresh;

=head2 as_json

Return process table as json.

    my $json_text = $uniman_proc->as_json;

=head2 as_hash

Return process table as hash.

    my %hash_with_uids = $uniman_proc->as_hash(1);

    my %hash_with_usernames = $uniman_proc->as_hash;

=head1 AUTHOR

Mugen Kenichi, C<< <mugen.kenichi at uninets.eu> >>

=head1 BUGS



( run in 0.922 second using v1.01-cache-2.11-cpan-9e1a9122474 )