line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Hailo::Storage::PostgreSQL; |
2
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:AVAR'; |
3
|
|
|
|
|
|
|
$Hailo::Storage::PostgreSQL::VERSION = '0.75'; |
4
|
4
|
|
|
4
|
|
4143
|
use v5.10.0; |
|
4
|
|
|
|
|
54
|
|
5
|
4
|
|
|
4
|
|
21
|
use Moose; |
|
4
|
|
|
|
|
21
|
|
|
4
|
|
|
|
|
32
|
|
6
|
4
|
|
|
4
|
|
25361
|
use MooseX::StrictConstructor; |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
30
|
|
7
|
4
|
|
|
4
|
|
12331
|
use namespace::clean -except => 'meta'; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
35
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
extends 'Hailo::Storage'; |
10
|
|
|
|
|
|
|
with qw(Hailo::Role::Arguments Hailo::Role::Storage); |
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
19
|
sub _build_dbd { return 'Pg' }; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
override _build_dbd_options => sub { |
15
|
|
|
|
|
|
|
return { |
16
|
|
|
|
|
|
|
%{ super() }, |
17
|
|
|
|
|
|
|
pg_enable_utf8 => 1, |
18
|
|
|
|
|
|
|
}; |
19
|
|
|
|
|
|
|
}; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub _build_dbi_options { |
22
|
1
|
|
|
1
|
|
2
|
my ($self) = @_; |
23
|
1
|
|
|
|
|
22
|
my $dbd = $self->dbd; |
24
|
1
|
|
|
|
|
23
|
my $dbd_options = $self->dbd_options; |
25
|
1
|
|
|
|
|
23
|
my $args = $self->arguments; |
26
|
|
|
|
|
|
|
|
27
|
1
|
|
|
|
|
3
|
my $conn_line = "dbi:$dbd"; |
28
|
1
|
50
|
|
|
|
5
|
$conn_line .= ":dbname=$args->{dbname}" if exists $args->{dbname}; |
29
|
1
|
50
|
|
|
|
4
|
$conn_line .= ";host=$args->{host}" if exists $args->{host}; |
30
|
1
|
50
|
|
|
|
4
|
$conn_line .= ";port=$args->{port}" if exists $args->{port}; |
31
|
1
|
50
|
|
|
|
3
|
$conn_line .= ";options=$args->{options}" if exists $args->{options}; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
my @options = ( |
34
|
|
|
|
|
|
|
$conn_line, |
35
|
|
|
|
|
|
|
($args->{username} || ''), |
36
|
1
|
|
50
|
|
|
13
|
($args->{password} || ''), |
|
|
|
50
|
|
|
|
|
37
|
|
|
|
|
|
|
$dbd_options, |
38
|
|
|
|
|
|
|
); |
39
|
|
|
|
|
|
|
|
40
|
1
|
|
|
|
|
24
|
return \@options; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub ready { |
44
|
4
|
|
|
4
|
0
|
9
|
my ($self) = @_; |
45
|
|
|
|
|
|
|
|
46
|
4
|
|
|
|
|
105
|
return exists $self->arguments->{dbname}; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=encoding utf8 |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=head1 NAME |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
Hailo::Storage::PostgreSQL - A storage backend for L<Hailo|Hailo> using L<DBD::Pg> |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head1 SYNOPSIS |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
First create a PostgreSQL database for failo: |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
# Run it as a dedicated hailo user |
62
|
|
|
|
|
|
|
createdb -E UTF8 -O hailo hailo |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
# Just create database.. |
65
|
|
|
|
|
|
|
createdb -E UTF8 hailo |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
As a module: |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
my $hailo = Hailo->new( |
70
|
|
|
|
|
|
|
storage_class => 'Pg', |
71
|
|
|
|
|
|
|
storage_args => { |
72
|
|
|
|
|
|
|
dbname => 'hailo', |
73
|
|
|
|
|
|
|
}, |
74
|
|
|
|
|
|
|
); |
75
|
|
|
|
|
|
|
$hailo->train("hailo.trn"); |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
Or with complex connection options: |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
my $hailo = Hailo->new( |
80
|
|
|
|
|
|
|
storage_class => 'Pg', |
81
|
|
|
|
|
|
|
storage_args => { |
82
|
|
|
|
|
|
|
dbname => 'hailo', |
83
|
|
|
|
|
|
|
host => 'localhost', |
84
|
|
|
|
|
|
|
port => '5432', |
85
|
|
|
|
|
|
|
options => '...', |
86
|
|
|
|
|
|
|
username => 'hailo', |
87
|
|
|
|
|
|
|
password => 'hailo' |
88
|
|
|
|
|
|
|
}, |
89
|
|
|
|
|
|
|
); |
90
|
|
|
|
|
|
|
$hailo->train("hailo.trn"); |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
From the command line: |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
hailo --train hailo.trn \ |
95
|
|
|
|
|
|
|
--storage Pg \ |
96
|
|
|
|
|
|
|
--storage-args dbname=hailo |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
Or with complex connection options: |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
hailo --train hailo.trn \ |
101
|
|
|
|
|
|
|
--storage Pg \ |
102
|
|
|
|
|
|
|
--storage-args dbname=hailo \ |
103
|
|
|
|
|
|
|
--storage-args host=localhost \ |
104
|
|
|
|
|
|
|
--storage-args port=5432 \ |
105
|
|
|
|
|
|
|
--storage-args options=... \ |
106
|
|
|
|
|
|
|
--storage-args username=hailo \ |
107
|
|
|
|
|
|
|
--storage-args password=hailo |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
Almost all of these options can be omitted, see L<DBD::Pg's |
110
|
|
|
|
|
|
|
documentation|DBD::Pg/"connect"> for the default values. |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
See L<Hailo's documentation|Hailo> for other non-Pg specific options. |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head1 DESCRIPTION |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
This backend maintains information in a PostgreSQL database. |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=head2 C<storage_args> |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
This is a hash reference which can have the following keys: |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
B<'dbname'>, the name of the database to use (required). |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
B<'host'>, the host to connect to (required). |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
B<'port'>, the port to connect to (required). |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
B<'options'>, additional options to pass to PostgreSQL. |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
B<'username'>, the username to use. |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
B<'password'>, the password to use. |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head1 AUTHOR |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
E<AElig>var ArnfjE<ouml>rE<eth> Bjarmason <avar@cpan.org> |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
Copyright 2010 E<AElig>var ArnfjE<ouml>rE<eth> Bjarmason. |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
This program is free software, you can redistribute it and/or modify |
145
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=cut |