line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Deeme::Backend::Meerkat; |
2
|
2
|
|
|
2
|
|
31171
|
use Deeme::Obj 'Deeme::Backend'; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
9
|
|
3
|
2
|
|
|
2
|
|
2223
|
use Meerkat; |
|
2
|
|
|
|
|
3716456
|
|
|
2
|
|
|
|
|
77
|
|
4
|
2
|
|
|
2
|
|
1002
|
use Deeme::Utils qw(_serialize _deserialize); |
|
2
|
|
|
|
|
553
|
|
|
2
|
|
|
|
|
100
|
|
5
|
2
|
|
|
2
|
|
10
|
use Carp 'croak'; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
1059
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
has [qw(database host username password meerkat)]; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub new { |
12
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
13
|
0
|
|
|
|
|
|
$self = $self->SUPER::new(@_); |
14
|
0
|
|
|
|
|
|
my $opts = {}; |
15
|
0
|
0
|
|
|
|
|
croak "No database defined" if ( !$self->database ); |
16
|
0
|
|
0
|
|
|
|
$opts->{host} = $self->host || croak "No host defined"; |
17
|
0
|
0
|
|
|
|
|
$opts->{username} = $self->username if ( $self->username ); |
18
|
0
|
0
|
|
|
|
|
$opts->{password} = $self->password if ( $self->password ); |
19
|
0
|
|
|
|
|
|
$self->meerkat( |
20
|
|
|
|
|
|
|
Meerkat->new( |
21
|
|
|
|
|
|
|
model_namespace => "Deeme::Backend::Meerkat::Model", |
22
|
|
|
|
|
|
|
database_name => $self->database, |
23
|
|
|
|
|
|
|
client_options => $opts, |
24
|
|
|
|
|
|
|
) |
25
|
|
|
|
|
|
|
); |
26
|
0
|
|
|
|
|
|
return $self; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub events_get { |
30
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
31
|
0
|
|
|
|
|
|
my $name = shift; |
32
|
0
|
|
0
|
|
|
|
my $deserialize = shift // 1; |
33
|
0
|
|
|
|
|
|
my $event |
34
|
|
|
|
|
|
|
= $self->meerkat->collection("Event")->find_one( { name => $name } ); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
#deserializing subs and returning a reference |
37
|
0
|
0
|
|
|
|
|
return undef if ( !$event ); |
38
|
0
|
0
|
|
|
|
|
return [ map { _deserialize($_) } @{ $event->functions() } ] |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
if ( $deserialize == 1 ); |
40
|
0
|
|
|
|
|
|
return $event->functions(); |
41
|
|
|
|
|
|
|
} #get events |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub events_reset { |
44
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
45
|
0
|
|
|
|
|
|
my $events = $self->meerkat->collection("Event")->find( {} ); |
46
|
0
|
|
|
|
|
|
while ( my $event = $events->next ) { |
47
|
0
|
|
|
|
|
|
$event->remove(); |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub events_onces { |
52
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
53
|
0
|
|
|
|
|
|
my $name = shift; |
54
|
0
|
|
|
|
|
|
my $event |
55
|
|
|
|
|
|
|
= $self->meerkat->collection("Event")->find_one( { name => $name } ); |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
#deserializing subs and returning a reference |
58
|
0
|
|
|
|
|
|
return @{ $event->onces() }; |
|
0
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
} #get events |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub once_update { |
62
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
63
|
0
|
|
|
|
|
|
my $name = shift; |
64
|
0
|
|
|
|
|
|
my $onces = shift; |
65
|
0
|
|
|
|
|
|
$self->meerkat->collection("Event")->find_one( { name => $name } ) |
66
|
|
|
|
|
|
|
->update_set( onces => $onces ); |
67
|
|
|
|
|
|
|
} #get events |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub event_add { |
70
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
71
|
0
|
|
|
|
|
|
my $name = shift; |
72
|
0
|
|
|
|
|
|
my $cb = shift; |
73
|
0
|
|
0
|
|
|
|
my $once = shift // 0; |
74
|
0
|
|
|
|
|
|
$cb = _serialize($cb); |
75
|
0
|
0
|
|
|
|
|
return $cb |
76
|
|
|
|
|
|
|
if ( $self->meerkat->collection("Event") |
77
|
|
|
|
|
|
|
->find_one( { name => $name, functions => $cb } ) ) |
78
|
|
|
|
|
|
|
; #return if already existing |
79
|
|
|
|
|
|
|
# serializing sub and adding to db |
80
|
0
|
0
|
|
|
|
|
if ( my $event |
81
|
|
|
|
|
|
|
= $self->meerkat->collection("Event")->find_one( { name => $name } ) ) |
82
|
|
|
|
|
|
|
{ |
83
|
0
|
|
|
|
|
|
$event->update_push( functions => $cb ); |
84
|
0
|
|
|
|
|
|
$event->update_push( onces => $once ); |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
else { |
87
|
0
|
|
|
|
|
|
my $event = $self->meerkat->collection("Event")->create( |
88
|
|
|
|
|
|
|
name => $name, |
89
|
|
|
|
|
|
|
functions => [$cb], |
90
|
|
|
|
|
|
|
onces => [$once] |
91
|
|
|
|
|
|
|
); |
92
|
|
|
|
|
|
|
} |
93
|
0
|
|
|
|
|
|
return $cb; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub event_delete { |
97
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
98
|
0
|
|
|
|
|
|
my $name = shift; |
99
|
0
|
|
|
|
|
|
$self->meerkat->collection("Event")->find_one( { name => $name } ) |
100
|
|
|
|
|
|
|
->remove(); |
101
|
|
|
|
|
|
|
} #delete event |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub event_update { |
104
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
105
|
0
|
|
|
|
|
|
my $name = shift; |
106
|
0
|
|
|
|
|
|
my $functions = shift; |
107
|
0
|
|
0
|
|
|
|
my $serialize = shift // 1; |
108
|
0
|
0
|
|
|
|
|
return $self->event_delete($name) if ( scalar( @{$functions} ) == 0 ); |
|
0
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
return $self->meerkat->collection("Event")->find_one( { name => $name } ) |
110
|
0
|
0
|
|
|
|
|
->update_set( functions => [ map { _serialize($_) } @{$functions} ] ) |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
if ( $serialize == 1 ); |
112
|
0
|
|
|
|
|
|
$self->meerkat->collection("Event")->find_one( { name => $name } ) |
113
|
|
|
|
|
|
|
->update_set( functions => $functions ); |
114
|
|
|
|
|
|
|
} #update event |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
package Deeme::Backend::Meerkat::Model::Event; |
117
|
2
|
|
|
2
|
|
8
|
use Moose; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
13
|
|
118
|
|
|
|
|
|
|
with 'Meerkat::Role::Document'; |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
has name => ( |
121
|
|
|
|
|
|
|
is => 'ro', |
122
|
|
|
|
|
|
|
isa => 'Str', |
123
|
|
|
|
|
|
|
required => 1, |
124
|
|
|
|
|
|
|
); |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
has functions => ( |
127
|
|
|
|
|
|
|
is => 'ro', |
128
|
|
|
|
|
|
|
isa => 'ArrayRef', |
129
|
|
|
|
|
|
|
); |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
has onces => ( |
132
|
|
|
|
|
|
|
is => 'ro', |
133
|
|
|
|
|
|
|
isa => 'ArrayRef' |
134
|
|
|
|
|
|
|
); |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
1; |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
__END__ |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=encoding utf-8 |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=head1 NAME |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
Deeme::Backend::Meerkat - MongoDB Backend using Meerkat for Deeme |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=head1 SYNOPSIS |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
use Deeme::Backend::Meerkat; |
149
|
|
|
|
|
|
|
my $e = Deeme->new( backend => Deeme::Backend::Meerkat->new( |
150
|
|
|
|
|
|
|
database => "deeme", |
151
|
|
|
|
|
|
|
host => "mongodb://localhost:27017", |
152
|
|
|
|
|
|
|
username=>"some", |
153
|
|
|
|
|
|
|
password=>"password" |
154
|
|
|
|
|
|
|
) ); |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=head1 DESCRIPTION |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
Deeme::Backend::Meerkat is a MongoDB Deeme database backend using Meerkat. |
159
|
|
|
|
|
|
|
Only database and host are strictly required. |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=head1 AUTHOR |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
mudler E<lt>mudler@dark-lab.netE<gt> |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=head1 COPYRIGHT |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
Copyright 2014- mudler |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=head1 LICENSE |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
172
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=head1 SEE ALSO |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
L<Deeme> |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=cut |