| 1 | 1 | ▶ | use 5.008001; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 2 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 3 | 1 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | |||
| 5 | package Dancer::Plugin::Queue::MongoDB; | ||
| 6 | # ABSTRACT: Dancer::Plugin::Queue backend using MongoDB | ||
| 7 | 1 | our $VERSION = '0.003'; # VERSION | |
| 8 | |||
| 9 | # Dependencies | ||
| 10 | 1 | ▶ | use Moose; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 11 | 1 | ▶ | use MooseX::AttributeShortcuts; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 12 | 1 | ▶ | use MongoDBx::Queue 1.000; # new API |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 13 | 1 | ▶ | use namespace::autoclean; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 14 | |||
| 15 | 1 | with 'Dancer::Plugin::Queue::Role::Queue'; | |
| 16 | |||
| 17 | |||
| 18 | 1 | has db_name => ( | |
| 19 | is => 'ro', | ||
| 20 | isa => 'Str', | ||
| 21 | required => 1, | ||
| 22 | ); | ||
| 23 | |||
| 24 | |||
| 25 | 1 | has queue_name => ( | |
| 26 | is => 'ro', | ||
| 27 | isa => 'Str', | ||
| 28 | default => 'queue', | ||
| 29 | ); | ||
| 30 | |||
| 31 | |||
| 32 | has connection_options => ( | ||
| 33 | is => 'ro', | ||
| 34 | isa => 'HashRef', | ||
| 35 | 0 | ▶ | default => sub { {} }, |
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||
| 36 | 1 | ); | |
| 37 | |||
| 38 | |||
| 39 | 1 | has queue => ( | |
| 40 | is => 'lazy', | ||
| 41 | isa => 'MongoDBx::Queue', | ||
| 42 | ); | ||
| 43 | |||
| 44 | 0 | ▶ | sub _build_queue { |
|
Subroutine
_build_queue: not called CC=1 SCAR=6.9
| |||
| 45 | 0 | my ($self) = @_; | |
| 46 | 0 | return MongoDBx::Queue->new( | |
| 47 | database_name => $self->db_name, | ||
| 48 | collection_name => $self->queue_name, | ||
| 49 | client_options => $self->connection_options, | ||
| 50 | ); | ||
| 51 | } | ||
| 52 | |||
| 53 | 0 | ▶ | sub add_msg { |
|
Subroutine
add_msg: not called CC=1 SCAR=6.9
Pod
undocumented
| |||
| 54 | 0 | my ( $self, $data ) = @_; | |
| 55 | 0 | $self->queue->add_task( { data => $data } ); | |
| 56 | } | ||
| 57 | |||
| 58 | 0 | ▶ | sub get_msg { |
|
Subroutine
get_msg: not called CC=1 SCAR=6.9
Pod
undocumented
| |||
| 59 | 0 | my ($self) = @_; | |
| 60 | 0 | my $msg = $self->queue->reserve_task; | |
| 61 | 0 | return ( $msg, $msg->{data} ); | |
| 62 | } | ||
| 63 | |||
| 64 | 0 | ▶ | sub remove_msg { |
|
Subroutine
remove_msg: not called CC=1 SCAR=6.9
Pod
undocumented
| |||
| 65 | 0 | my ( $self, $msg ) = @_; | |
| 66 | 0 | $self->queue->remove_task($msg); | |
| 67 | } | ||
| 68 | |||
| 69 | 1 | __PACKAGE__->meta->make_immutable; | |
| 70 | |||
| 71 | 1 | 1; | |
| 72 | |||
| 73 | |||
| 74 | # vim: ts=2 sts=2 sw=2 et: | ||
| 75 | |||
| 76 | __END__ | ||