Net-Telnet-Gearman

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN


0.05000     Thu Jan 16 2014
            - Do not bundle MYMETA* files.

0.04000     Sun Oct 21 2012
            - Bundle Module::Install 1.06
              See also: http://goo.gl/TXzhQ

0.03000     Thu Feb 16 2012
            - Skip function lines that do not return numbers for
              the busy, queue or running columns
            - Proxy arguments given to status and workers method
              to the Net::Telnet getline method

0.02000     Thu Mar 11 2010
            - Refactor ::Function and ::Worker to be testable
              plus add tests for it
            - Fix RT#55451

0.01000     Thu Nov 01 2009
            - Initial release.

lib/Net/Telnet/Gearman/Function.pm  view on Meta::CPAN

package Net::Telnet::Gearman::Function;

use strict;
use warnings;
use base qw/Class::Accessor::Fast/;
use Scalar::Util qw(looks_like_number);

__PACKAGE__->mk_accessors(qw/name queue busy free running/);

sub parse_line {
    my ( $package, $line ) = @_;

    my ( $name, $queue, $busy, $running ) = split /[\s]+/, $line;

    return
      if !looks_like_number($queue)
          || !looks_like_number($busy)
          || !looks_like_number($running);

    my $free = $running - $busy;

    return $package->new(
        {
            name    => $name,
            queue   => $queue,
            busy    => $busy,
            free    => $free,
            running => $running,
        }
    );
}

=head1 NAME

Net::Telnet::Gearman::Function

lib/Net/Telnet/Gearman/Function.pm  view on Meta::CPAN

        Host => '127.0.0.1',
        Port => 4730,
    );
    
    my @functions = $session->status();
    
    print Dumper @functions
    
    # $VAR1 = bless(
    #     {
    #         'busy'    => 10,
    #         'free'    => 0,
    #         'name'    => 'resize_image',
    #         'queue'   => 74,
    #         'running' => 10
    #     },
    #     'Net::Telnet::Gearman::Function'
    # );

=head1 METHODS

=head2 name

Returns the name of the function.

=head2 queue

Returns the amount of queued jobs for this function.

=head2 busy

Returns the amount of workers currently working on this function.

=head2 free

Returns the amount of free workers that can do this function.

=head2 running

Returns the amount of running workers registered for this function.

t/02-function.t  view on Meta::CPAN

use strict;
use warnings;
use Test::More tests => 8;
use Net::Telnet::Gearman::Function;

my @tests = (
    {
        line     => 'reverse 3       3       12',
        expected => {
            'busy'    => 3,
            'free'    => 9,
            'name'    => 'reverse',
            'queue'   => 3,
            'running' => 12,
        }
    },
);

foreach my $test (@tests) {
    my $w = Net::Telnet::Gearman::Function->parse_line( $test->{line} );



( run in 0.256 second using v1.01-cache-2.11-cpan-3cd7ad12f66 )