blib/lib/Sque/Job.pm

filter: Statementstmt 94.5% 52 / 55 Branchbran 62.5% 5 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 84.2% 16 / 19 Podpod 100% 4 / 4 totaltotal 89.5% 77 / 86 CC 5 SCAR 5.6
CC
5
Cov
90%
perform
4.0
__ANON__
2.0
__ANON__
2.0
CRAP 1.7
« blib/lib/App/Sque.pm ↑ Summary blib/lib/Sque/Encoder.pm »
1 package Sque::Job;
2 6 $Sque::Job::VERSION = '0.010';
3 6 ▶use Any::Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 6 ▶use Any::Moose '::Util::TypeConstraints';
Subroutine BEGIN: called CC=1 SCAR=0.0
5 6 ▶use UNIVERSAL::require;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 6 with 'Sque::Encoder';
7  
8 # ABSTRACT: Sque job container
9  
10 has sque => (
11 is => 'rw',
12 handles => [qw/ stomp /],
13 0 ▶ default => sub { confess "This Sque::Job isn't associated to any Sque system yet!" }
Subroutine __ANON__: not called CC=1 SCAR=6.9
14 6 );
15  
16 has worker => (
17 is => 'rw',
18 lazy => 1,
19 0 ▶ default => sub { $_[0]->sque->worker },
Subroutine __ANON__: not called CC=1 SCAR=6.9
20 6 predicate => 'has_worker'
21 );
22  
23 has class => (
24 is => 'rw',
25 lazy => 1,
26 0 ▶ default => sub { confess "This job needs a class to do some work." },
Subroutine __ANON__: not called CC=1 SCAR=6.9
27 6 );
28  
29 6 has queue => (
30 is => 'rw',
31 lazy => 1,
32 default => \&queue_from_class,
33 predicate => 'queued'
34 );
35  
36 4 ▶has args => ( is => 'rw', isa => 'ArrayRef', default => sub {[]} );
Subroutine __ANON__: called CC=1 SCAR=0.0
37  
38 coerce 'HashRef'
39 => from 'Str'
40 2 ▶ => via { JSON->new->utf8->decode($_) };
Subroutine __ANON__: called CC=1 SCAR=0.0
41  
42 has payload => (
43 is => 'rw',
44 isa => 'HashRef',
45 coerce => 1,
46 lazy => 1,
47 2 ▶ default => sub {{
Subroutine __ANON__: called CC=1 SCAR=0.0
48 2 class => $_[0]->class,
49 args => $_[0]->args,
50 }},
51 2 ▶ trigger => sub {
Subroutine __ANON__: called CC=2 SCAR=7.1
52 2 my ( $self, $hr ) = @_;
53 2 $self->class( $hr->{class} );
54 2 ▶ $self->args( $hr->{args} ) if $hr->{args};
Branch: 1 branch
BranchTrueFalseTotal
if $hr->{"args"} 2 0 2
55 }
56 6 );
57  
58 has headers => (
59 is => 'rw',
60 isa => 'HashRef',
61 6 ▶ default => sub{ {} },
Subroutine __ANON__: called CC=1 SCAR=0.0
62 6 );
63  
64 has frame => (
65 is => 'ro',
66 lazy => 1,
67 1 ▶ default => sub { {} },
Subroutine __ANON__: called CC=1 SCAR=0.0
68 2 ▶ trigger => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
69 2 my ( $self, $frame ) = @_;
70 2 $self->payload( $frame->body );
71 }
72 6 );
73  
74 2 ▶sub encode {
Subroutine encode: called CC=1 SCAR=0.0
Pod documented
75 2 my $self = shift;
76 2 $self->encoder->encode( $self->payload );
77 }
78  
79 3 ▶sub stringify {
Subroutine stringify: called CC=1 SCAR=0.0
Pod documented
80 3 my $self = shift;
81 3 sprintf( "(Job{%s} | %s | %s)",
82 $self->queue,
83 $self->class,
84 $self->encoder->encode( $self->args )
85 );
86 }
87 1 ▶sub queue_from_class {
Subroutine queue_from_class: called CC=1 SCAR=0.0
Pod documented
88 1 my $class = shift->class;
89 1 $class =~ s/://g;
90 1 $class;
91 }
92  
93 3 ▶sub perform {
Subroutine perform: called CC=4 SCAR=13.9
Pod documented
94 3 my $self = shift;
95 3 ▶ $self->class->require || confess $@;
Branch: 1 branch
BranchTrueFalseTotal
$self->class->require or confess($@) 3 0 3
96  
97 # First test if its OO
98 3 ▶ if($self->class->can('new')){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->class->can('new')) { } 1 2 3
99 6 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
100 1 $self->class->new->perform( $self );
101 }else{
102 # If it's not OO, just call perform
103 2 ▶ $self->class->can('perform')
Branch: 1 branch
BranchTrueFalseTotal
$self->class->can("perform") or confess($self->class . q[ doesn't know how to perform]) 2 0 2
104 || confess $self->class . " doesn't know how to perform";
105  
106 6 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
107 2 &{$self->class . '::perform'}($self);
108 }
109 }
110  
111 6 __PACKAGE__->meta->make_immutable();
112  
113 6 1;
114  
115 __END__
« blib/lib/App/Sque.pm ↑ Summary blib/lib/Sque/Encoder.pm »