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