| 1 | package Hailo::Storage::PostgreSQL; | ||||||||||||||||||||||
| 2 | 4 | our $AUTHORITY = 'cpan:AVAR'; | |||||||||||||||||||||
| 3 | 4 | $Hailo::Storage::PostgreSQL::VERSION = '0.74'; | |||||||||||||||||||||
| 4 | 4 | ▶ | use v5.28.0; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 5 | 4 | ▶ | use Moose; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 6 | 4 | ▶ | use MooseX::StrictConstructor; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 7 | 4 | ▶ | use namespace::clean -except => 'meta'; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 8 | |||||||||||||||||||||||
| 9 | 4 | extends 'Hailo::Storage'; | |||||||||||||||||||||
| 10 | 4 | with qw(Hailo::Role::Arguments Hailo::Role::Storage); | |||||||||||||||||||||
| 11 | |||||||||||||||||||||||
| 12 | 1 | ▶ | sub _build_dbd { return 'Pg' }; | ||||||||||||||||||||
|
Subroutine
_build_dbd: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 13 | |||||||||||||||||||||||
| 14 | override _build_dbd_options => sub { | ||||||||||||||||||||||
| 15 | return { | ||||||||||||||||||||||
| 16 | 2 | ▶ | %{ super() }, | ||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 17 | pg_enable_utf8 => 1, | ||||||||||||||||||||||
| 18 | }; | ||||||||||||||||||||||
| 19 | 4 | }; | |||||||||||||||||||||
| 20 | |||||||||||||||||||||||
| 21 | sub _build_dbi_options { | ||||||||||||||||||||||
| 22 | 1 | ▶ | my ($self) = @_; | ||||||||||||||||||||
|
Subroutine
_build_dbi_options: called CC=7 SCAR=20.6
| |||||||||||||||||||||||
| 23 | 1 | my $dbd = $self->dbd; | |||||||||||||||||||||
| 24 | 1 | my $dbd_options = $self->dbd_options; | |||||||||||||||||||||
| 25 | 1 | my $args = $self->arguments; | |||||||||||||||||||||
| 26 | |||||||||||||||||||||||
| 27 | 1 | my $conn_line = "dbi:$dbd"; | |||||||||||||||||||||
| 28 | 1 | ▶ | $conn_line .= ":dbname=$args->{dbname}" if exists $args->{dbname}; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 29 | 1 | ▶ | $conn_line .= ";host=$args->{host}" if exists $args->{host}; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 30 | 1 | ▶ | $conn_line .= ";port=$args->{port}" if exists $args->{port}; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 31 | 1 | ▶ | $conn_line .= ";options=$args->{options}" if exists $args->{options}; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 32 | |||||||||||||||||||||||
| 33 | my @options = ( | ||||||||||||||||||||||
| 34 | $conn_line, | ||||||||||||||||||||||
| 35 | ($args->{username} || ''), | ||||||||||||||||||||||
| 36 | 1 | ▶ | ($args->{password} || ''), | ||||||||||||||||||||
|
Condition50%2/4
$args->{'username'} || ''
$args->{'password'} || ''
MC/DC0%0/1
$args->{'username'} || ''
$args->{'username'}
MC/DC0%0/1
$args->{'password'} || ''
$args->{'password'}
Truth table50%1/2
A
A= $args->{'username'}
Truth table50%1/2
A
A= $args->{'password'}
| |||||||||||||||||||||||
| 37 | $dbd_options, | ||||||||||||||||||||||
| 38 | ); | ||||||||||||||||||||||
| 39 | |||||||||||||||||||||||
| 40 | 1 | return \@options; | |||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||
| 42 | |||||||||||||||||||||||
| 43 | sub ready { | ||||||||||||||||||||||
| 44 | 4 | ▶ | my ($self) = @_; | ||||||||||||||||||||
|
Subroutine
ready: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||
| 45 | |||||||||||||||||||||||
| 46 | 4 | return exists $self->arguments->{dbname}; | |||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||
| 48 | |||||||||||||||||||||||
| 49 | 4 | __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 | ||||||||||||||||||||||