Collector/Output/Database/Base.pm

filter: Statementstmt 77.7% 7 / 9 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 3 / 3 Podpod n/a totaltotal 83.3% 10 / 12 CC 1 SCAR 0.9
CC
1
Cov
78%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
« Collector/Output/Database/Alerts.pm ↑ Summary Collector/Output/Database/Logs.pm »
1 package XAS::Collector::Output::Database::Base;
2  
3 our $VERSION = '0.01';
4  
5 1 ▶use POE;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use XAS::Model::Schema;
Subroutine BEGIN: called CC=1 SCAR=2.6
8 use XAS::Lib::POE::PubSub;
9  
10 use XAS::Class
11 debug => 0,
12 version => $VERSION,
13 base => 'XAS::Lib::POE::Service',
14 mixin => 'XAS::Lib::Mixins::Handlers',
15 utils => 'db2dt',
16 accessors => 'schema event',
17 vars => {
18 PARAMS => {
19 -database => { optional => 1, default => 'messaging' },
20 }
21 }
22 ;
23  
24 #use Data::Dumper;
25  
26 # --------------------------------------------------------------------
27 # Public Events
28 # --------------------------------------------------------------------
29  
30 # --------------------------------------------------------------------
31 # Public Methods
32 # --------------------------------------------------------------------
33  
34 sub session_initialize {
35 my $self = shift;
36  
37 my $alias = $self->alias;
38  
39 $self->log->debug("$alias: entering session_initialize()");
40  
41 $poe_kernel->state('store_data', $self);
42  
43 # walk the chain
44  
45 $self->SUPER::session_initialize();
46  
47 $self->log->debug("$alias: leaving session_initialize()");
48  
49 }
50  
51 sub session_startup {
52 my $self = shift;
53  
54 my $alias = $self->alias;
55  
56 $self->log->debug("$alias: entering session_startup()");
57  
58 $self->event->publish(
59 -event => 'start_queue',
60 -args => $alias
61 );
62  
63 # walk the chain
64  
65 $self->SUPER::session_startup();
66  
67 $self->log->debug("$alias: leasing session_startup()");
68  
69 }
70  
71 # --------------------------------------------------------------------
72 # Private Methods
73 # --------------------------------------------------------------------
74  
75 sub init {
76 my $class = shift;
77  
78 my $self = $class->SUPER::init(@_);
79  
80 $self->{'event'} = XAS::Lib::POE::PubSub->new();
81 $self->{'schema'} = XAS::Model::Schema->opendb($self->database);
82  
83 return $self;
84  
85 }
86  
87 1;
88  
89 __END__
90  
91 =head1 NAME
92  
93 XAS::Collector::Output::Database::Base - Perl extension for the XAS Environment
94  
95 =head1 SYNOPSIS
96  
97 use XAS::Collector::Output::Database::Logs;
98  
99 my $output = XAS::Collector::Output::Database::Logs->new(
100 -alias => 'database-logs',
101 -database => 'messaging',
102 );
103  
104 =head1 DESCRIPTION
105  
106 This module is the base class for database storage.
107  
108 =head1 METHODS
109  
110 =head2 new
111  
112 This module inheirts from L<XAS::Lib::POE::Service|XAS::Lib::POE::Service> and
113 takes these additional parameters:
114  
115 =over 4
116  
117 =item B<-database>
118  
119 An optional configuration name for the database to use, defaults to 'messaging'.
120  
121 =back
122  
123 =head1 PUBLIC EVENTS
124  
125 This module declares the following events.
126  
127 =head2 store_data
128  
129 This event is called when a packet is ready for processing.
130  
131 =head1 SEE ALSO
132  
133 =over 4
134  
135 =item L<XAS::Collector::Output::Database::Alerts|XAS::Collector::Output::Database::Alerts>
136  
137 =item L<XAS::Collector::Output::Database::Logs|XAS::Collector::Output::Database::Logs>
138  
139 =item L<XAS::Collector|XAS::Collector>
140  
141 =item L<XAS|XAS>
142  
143 =back
144  
145 =head1 AUTHOR
146  
147 Kevin Esteb, E<lt>kevin@kesteb.usE<gt>
148  
149 =head1 COPYRIGHT AND LICENSE
150  
151 Copyright (c) 2012-2015 Kevin L. Esteb
152  
153 This is free software; you can redistribute it and/or modify it under
154 the terms of the Artistic License 2.0. For details, see the full text
155 of the license at http://www.perlfoundation.org/artistic_license_2_0.
156  
157 =cut
« Collector/Output/Database/Alerts.pm ↑ Summary Collector/Output/Database/Logs.pm »