| 1 | 2 | ▶ | use 5.008001; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 2 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | package Dancer::Plugin::Queue; | ||||||||||||||||||||||||||||
| 6 | # ABSTRACT: Dancer plugin for message queue abstractions | ||||||||||||||||||||||||||||
| 7 | 2 | our $VERSION = '0.002'; # VERSION | |||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use Dancer::Plugin; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use Class::Load qw/try_load_class/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 2 | my %queues; | |||||||||||||||||||||||||||
| 13 | my $conf; | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 3 | ▶ | register queue => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=13 SCAR=30.3
| |||||||||||||||||||||||||||||
| 16 | 3 | my ( $self, $name ) = plugin_args(@_); | |||||||||||||||||||||||||||
| 17 | 3 | ▶ | $conf ||= plugin_setting(); | ||||||||||||||||||||||||||
|
Condition66%2/3
$conf ||= plugin_setting()
MC/DC0%0/2
$conf ||= plugin_setting()
$conf
plugin_setting()
Truth table66%2/3
A ||= B
A= $confB= plugin_setting()
| |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | # if name not specified, DWIM or use 'default' | ||||||||||||||||||||||||||||
| 20 | 3 | ▶ | if ( not defined $name ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 21 | 3 | ▶ | if ( keys %$conf == 1 ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 22 | 3 | ($name) = keys %$conf; | |||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||
| 24 | elsif ( exists $conf->{default} ) { | ||||||||||||||||||||||||||||
| 25 | 0 | $name = "default"; | |||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||
| 27 | else { | ||||||||||||||||||||||||||||
| 28 | 0 | die "Can't determine a default queue name"; | |||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | # return cached object if already created | ||||||||||||||||||||||||||||
| 33 | 3 | ▶ | return $queues{$name} if defined $queues{$name}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | # otherwise, instantiate the object from config settings | ||||||||||||||||||||||||||||
| 36 | 1 | ▶ | my $queue_conf = $conf->{$name} | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 37 | or die "No configuration for queue '$name'"; | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | my $class = $queue_conf->{class} | ||||||||||||||||||||||||||||
| 40 | 1 | ▶ | or die "No class specified for queue '$name'"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 1 | $class = "Dancer::Plugin::Queue::$class"; | |||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 1 | ▶ | try_load_class($class) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 45 | or die "Queue class '$class' could not be loaded"; | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 1 | ▶ | $class->can('DOES') && $class->DOES("Dancer::Plugin::Queue::Role::Queue") | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$class->can("DOES") and $class->DOES("Dancer::Plugin::Queue::Role::Queue")
MC/DC0%0/2
$class->can("DOES") and $class->DOES("Dancer::Plugin::Queue::Role::Queue")
$class->can("DOES")
$class->DOES("Dancer::Plugin::Queue::Role::Queue")
Truth table33%1/3
A and B
A= $class->can("DOES")B= $class->DOES("Dancer::Plugin::Queue::Role::Queue")
| |||||||||||||||||||||||||||||
| 48 | or die "Queue class '$class' does not implement the expected role"; | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 1 | ▶ | my $object = eval { $class->new( $queue_conf->{options} || {} ) } | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$queue_conf->{'options'} || {}
MC/DC0%0/1
$queue_conf->{'options'} || {}
$queue_conf->{'options'}
Truth table50%1/2
A
A= $queue_conf->{'options'}
| |||||||||||||||||||||||||||||
| 51 | or die "Could not create $class object: $@"; | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 1 | return $queues{$name} = $object; | |||||||||||||||||||||||||||
| 54 | 2 | }; | |||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 2 | register_plugin; | |||||||||||||||||||||||||||
| 57 | 2 | 1; | |||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | # vim: ts=4 sts=4 sw=4 et: | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | __END__ | ||||||||||||||||||||||||||||