File Coverage

blib/lib/App/LedgerSMB/Admin/Database/Setting.pm
Criterion Covered Total %
statement 6 14 42.8
branch n/a
condition n/a
subroutine 2 6 33.3
pod n/a
total 8 20 40.0


line stmt bran cond sub pod time code
1             =head1 NAME
2              
3             App::LedgerSMB::Admin::Database::Setting - Access LSMB Settings from Admin Tools
4              
5             =cut
6              
7             package App::LedgerSMB::Admin::Database::Setting;
8 2     2   12 use Moo;
  2         4  
  2         10  
9             with 'PGObject::Simple::Role';
10              
11 2     2   1290 use PGObject::Util::DBMethod;
  2         1156  
  2         396  
12              
13             sub _get_dbh {
14 0     0     my ($self) = @_;
15 0           return $self->database->connect;
16             }
17              
18 0     0     sub _get_prefix { 'setting_' };
19              
20             =head1 SYNOPSIS
21              
22             my $db = App::LedgerSMB::Admin::Database->new(
23             username => 'postgres',
24             password => 'secret',
25             host => 'localhost',
26             port => '5432',
27             );
28             my $setting = App::LedgerSMB::Admin::Database::Setting->new(
29             database => $db,
30             setting_key => 'separate_duties');
31             my $sep_duties = $setting->value;
32              
33             =head1 PROPERTIES
34              
35             =head2 database
36              
37             The database for the associated setting. Must be a
38             App::LedgerSMB:Admin::Database object
39              
40             =cut
41              
42             has database => (
43             is => 'ro',
44             isa => sub { die 'Must be a Database Object'
45             unless eval { $_[0]->isa('App::LedgerSMB::Admin::Database')};
46             }
47             );
48              
49             =head2 setting_key
50              
51             The name of the setting
52              
53             =cut
54              
55             has setting_key => (is => 'ro');
56              
57             =head2 value
58              
59             The value of the setting. Is looked up lazily.
60              
61             =cut
62              
63             has value => (is => 'lazy');
64              
65             sub _build_value {
66 0     0     my ($hash) = $_[0]->_get;
67 0           return $hash->{value};
68             }
69              
70             sub _get {
71 0     0     my ($self) = @_;
72 0           my ($hash) = $self->call_procedure(funcname => 'get', args => [$self->setting_key]);
73 0           return $hash;
74             }
75              
76             =head1 LICENSE AND COPYRIGHT
77              
78             Copyright 2014 Chris Travers.
79              
80             This program is distributed under the (Revised) BSD License:
81             L
82              
83             Redistribution and use in source and binary forms, with or without
84             modification, are permitted provided that the following conditions
85             are met:
86              
87             * Redistributions of source code must retain the above copyright
88             notice, this list of conditions and the following disclaimer.
89              
90             * Redistributions in binary form must reproduce the above copyright
91             notice, this list of conditions and the following disclaimer in the
92             documentation and/or other materials provided with the distribution.
93              
94             * Neither the name of Chris Travers's Organization
95             nor the names of its contributors may be used to endorse or promote
96             products derived from this software without specific prior written
97             permission.
98              
99             THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
100             "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
101             LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
102             A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
103             OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
104             SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
105             LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
106             DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
107             THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
108             (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
109             OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
110              
111             =cut
112              
113             1;