line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
327207
|
use 5.008001; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
43
|
|
2
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
28
|
|
3
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
55
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Dancer::Plugin::Queue; |
6
|
|
|
|
|
|
|
# ABSTRACT: Dancer plugin for message queue abstractions |
7
|
|
|
|
|
|
|
our $VERSION = '0.002'; # VERSION |
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
886
|
use Dancer::Plugin; |
|
1
|
|
|
|
|
1444
|
|
|
1
|
|
|
|
|
90
|
|
10
|
1
|
|
|
1
|
|
912
|
use Class::Load qw/try_load_class/; |
|
1
|
|
|
|
|
27351
|
|
|
1
|
|
|
|
|
407
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
my %queues; |
13
|
|
|
|
|
|
|
my $conf; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
register queue => sub { |
16
|
3
|
|
|
3
|
|
3499
|
my ( $self, $name ) = plugin_args(@_); |
17
|
3
|
|
66
|
|
|
19
|
$conf ||= plugin_setting(); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# if name not specified, DWIM or use 'default' |
20
|
3
|
50
|
|
|
|
32
|
if ( not defined $name ) { |
21
|
3
|
50
|
|
|
|
11
|
if ( keys %$conf == 1 ) { |
|
|
0
|
|
|
|
|
|
22
|
3
|
|
|
|
|
7
|
($name) = keys %$conf; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
elsif ( exists $conf->{default} ) { |
25
|
0
|
|
|
|
|
0
|
$name = "default"; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
else { |
28
|
0
|
|
|
|
|
0
|
die "Can't determine a default queue name"; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
# return cached object if already created |
33
|
3
|
100
|
|
|
|
33
|
return $queues{$name} if defined $queues{$name}; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
# otherwise, instantiate the object from config settings |
36
|
1
|
50
|
|
|
|
5
|
my $queue_conf = $conf->{$name} |
37
|
|
|
|
|
|
|
or die "No configuration for queue '$name'"; |
38
|
|
|
|
|
|
|
|
39
|
1
|
50
|
|
|
|
4
|
my $class = $queue_conf->{class} |
40
|
|
|
|
|
|
|
or die "No class specified for queue '$name'"; |
41
|
|
|
|
|
|
|
|
42
|
1
|
|
|
|
|
3
|
$class = "Dancer::Plugin::Queue::$class"; |
43
|
|
|
|
|
|
|
|
44
|
1
|
50
|
|
|
|
6
|
try_load_class($class) |
45
|
|
|
|
|
|
|
or die "Queue class '$class' could not be loaded"; |
46
|
|
|
|
|
|
|
|
47
|
1
|
50
|
33
|
|
|
66
|
$class->can('DOES') && $class->DOES("Dancer::Plugin::Queue::Role::Queue") |
48
|
|
|
|
|
|
|
or die "Queue class '$class' does not implement the expected role"; |
49
|
|
|
|
|
|
|
|
50
|
1
|
50
|
50
|
|
|
34
|
my $object = eval { $class->new( $queue_conf->{options} || {} ) } |
|
1
|
|
|
|
|
8
|
|
51
|
|
|
|
|
|
|
or die "Could not create $class object: $@"; |
52
|
|
|
|
|
|
|
|
53
|
1
|
|
|
|
|
19
|
return $queues{$name} = $object; |
54
|
|
|
|
|
|
|
}; |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
register_plugin; |
57
|
|
|
|
|
|
|
1; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
# vim: ts=4 sts=4 sw=4 et: |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
__END__ |