lib/POE/Component/MessageQueue/Storage/DBI.pm

filter: Statementstmt 88.8% 16 / 18 Branchbran 50.0% 1 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 3 / 3 Podpod 0.0% 0 / 1 totaltotal 83.3% 20 / 24 CC 2 SCAR 4.5
CC
2
Cov
85%
__ANON__
2.1
BEGIN
1.0
BUILD
1.0
CRAP 1.6
« lib/POE/Component/MessageQueue/Storage.pm ↑ Summary lib/POE/Component/MessageQueue/Client.pm »
1 #
2 # Copyright 2007-2010 David Snopek <dsnopek@gmail.com>
3 #
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation, either version 2 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 #
17  
18 package POE::Component::MessageQueue::Storage::DBI;
19 13 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 13 extends qw(POE::Component::MessageQueue::Storage::Generic);
21  
22 13 has '+package' => (
23 default => 'POE::Component::MessageQueue::Storage::Generic::DBI',
24 );
25  
26 around new => sub {
27 7 ▶ my ($original, $class) = (shift, shift);
Subroutine __ANON__: called CC=2 SCAR=7.6
28 7 my @args;
29 7 ▶ if (ref($_[0]) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0] eq 'HASH') { } 0 7 7
30 0 @args = %{$_[0]};
31 } else {
32 7 @args = @_;
33 }
34 7 $original->($class, @args, options => \@args);
35 13 };
36  
37 sub BUILD {
38 7 ▶ my ($self) = @_;
Subroutine BUILD: called CC=1 SCAR=0.0
Pod undocumented
39 # Forces early termination if we cannot connect to db.
40 7 eval 'require ' . $self->package;
41 7 $self->package->new(@{$self->options});
42 }
43  
44 13 1;
45  
46 __END__
47  
48 =pod
49  
50 =head1 NAME
51  
52 POE::Component::MessageQueue::Storage::DBI -- A storage engine that uses L<DBI>
53  
54 =head1 SYNOPSIS
55  
56 use POE;
57 use POE::Component::MessageQueue;
58 use POE::Component::MessageQueue::Storage::DBI;
59 use strict;
60  
61 # For mysql:
62 my $DB_DSN = 'DBI:mysql:database=perl_mq';
63 my $DB_USERNAME = 'perl_mq';
64 my $DB_PASSWORD = 'perl_mq';
65 my $DB_OPTIONS = undef;
66  
67 POE::Component::MessageQueue->new({
68 storage => POE::Component::MessageQueue::Storage::DBI->new({
69 dsn => $DB_DSN,
70 username => $DB_USERNAME,
71 password => $DB_PASSWORD,
72 options => $DB_OPTIONS
73 })
74 });
75  
76 POE::Kernel->run();
77 exit;
78  
79 =head1 DESCRIPTION
80  
81 A storage engine that uses L<DBI>. All messages stored with this backend are
82 persisted.
83  
84 Performance is increased greatly by wrapping this engine in
85 L<POE::Component::MessageQueue::Storage::Throttled> at the expense of being slower
86 to persist messages.
87  
88 This module is really just L<POE::Component::MessageQueue::Storage::Generic> with
89 L<POE::Component::MessageQueue::Storage::Generic::DBI>. See the documentation for
90 those modules for more information (primarily
91 L<POE::Component::MessageQueue::Storage::Generic::DBI>).
92  
93 =head1 CONSTRUCTOR PARAMETERS
94  
95 =over 2
96  
97 =item dsn => SCALAR
98  
99 =item username => SCALAR
100  
101 =item password => SCALAR
102  
103 =item options => SCALAR
104  
105 =item mq_id => SCALAR
106  
107 =back
108  
109 =head1 SEE ALSO
110  
111 L<POE::Component::MessageQueue>,
112 L<POE::Component::MessageQueue::Storage>,
113 L<DBI>
114  
115 I<Other storage engines:>
116  
117 L<POE::Component::MessageQueue::Storage::Memory>,
118 L<POE::Component::MessageQueue::Storage::BigMemory>,
119 L<POE::Component::MessageQueue::Storage::FileSystem>,
120 L<POE::Component::MessageQueue::Storage::Generic>,
121 L<POE::Component::MessageQueue::Storage::Generic::DBI>,
122 L<POE::Component::MessageQueue::Storage::Throttled>,
123 L<POE::Component::MessageQueue::Storage::Complex>,
124 L<POE::Component::MessageQueue::Storage::Default>
125  
126 =cut
127  
« lib/POE/Component/MessageQueue/Storage.pm ↑ Summary lib/POE/Component/MessageQueue/Client.pm »