| 1 | package OpusVL::SysParams; | ||||||||||
| 2 | |||||||||||
| 3 | 4 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 4 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 4 | ▶ | use JSON; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 4 | ▶ | use Data::Munge qw/elem/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 4 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | has 'schema' => (isa => 'DBIx::Class::Schema', is => 'ro', required => 1, | ||||||||||
| 11 | default => sub | ||||||||||
| 12 | 1 | ▶ | { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 13 | # this means we only load Config::JFDI and create our schema if they | ||||||||||
| 14 | # don't specify their own schema. | ||||||||||
| 15 | 1 | require Config::JFDI; | |||||||||
| 16 | 1 | require OpusVL::SysParams::Schema; | |||||||||
| 17 | 1 | my $config = Config::JFDI->new(name => __PACKAGE__); | |||||||||
| 18 | 1 | my $config_hash = $config->get; | |||||||||
| 19 | 1 | my $schema = OpusVL::SysParams::Schema->connect( @{$config_hash->{'Model::SysParams'}->{connect_info}} ); | |||||||||
| 20 | 1 | return $schema; | |||||||||
| 21 | } | ||||||||||
| 22 | 4 | ); | |||||||||
| 23 | |||||||||||
| 24 | # ABSTRACT: Module to handle system wide parameters | ||||||||||
| 25 | |||||||||||
| 26 | |||||||||||
| 27 | 4 | our $VERSION = '0.20'; | |||||||||
| 28 | |||||||||||
| 29 | |||||||||||
| 30 | |||||||||||
| 31 | 10 | ▶ | sub get { | ||||||||
|
Subroutine
get: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 32 | 10 | my $self = shift; | |||||||||
| 33 | 10 | my $schema = $self->schema; | |||||||||
| 34 | 10 | return $schema->resultset('SysInfo')->get(@_); | |||||||||
| 35 | } | ||||||||||
| 36 | |||||||||||
| 37 | |||||||||||
| 38 | 2 | ▶ | sub get_or_set { | ||||||||
|
Subroutine
get_or_set: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 39 | 2 | my ($self, $name, $default_sub, $type) = @_; | |||||||||
| 40 | 2 | ▶ | if (elem $name, [$self->key_names]) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 41 | 1 | return $self->get($name); | |||||||||
| 42 | } | ||||||||||
| 43 | else { | ||||||||||
| 44 | 1 | my $value = $default_sub->($self); | |||||||||
| 45 | 1 | $self->set($name, $value, $type); | |||||||||
| 46 | 1 | return $value; | |||||||||
| 47 | } | ||||||||||
| 48 | } | ||||||||||
| 49 | |||||||||||
| 50 | |||||||||||
| 51 | 1 | ▶ | sub del { | ||||||||
|
Subroutine
del: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 52 | 1 | my $self = shift; | |||||||||
| 53 | 1 | my $schema = $self->schema; | |||||||||
| 54 | 1 | return $schema->resultset('SysInfo')->del(@_); | |||||||||
| 55 | } | ||||||||||
| 56 | |||||||||||
| 57 | |||||||||||
| 58 | 5 | ▶ | sub key_names { | ||||||||
|
Subroutine
key_names: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 59 | 5 | my $self = shift; | |||||||||
| 60 | 5 | my $schema = $self->schema; | |||||||||
| 61 | 5 | return $schema->resultset('SysInfo')->key_names(@_); | |||||||||
| 62 | } | ||||||||||
| 63 | |||||||||||
| 64 | |||||||||||
| 65 | 6 | ▶ | sub set { | ||||||||
|
Subroutine
set: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 66 | 6 | my $self = shift; | |||||||||
| 67 | 6 | my $schema = $self->schema; | |||||||||
| 68 | 6 | return $schema->resultset('SysInfo')->set(@_); | |||||||||
| 69 | } | ||||||||||
| 70 | |||||||||||
| 71 | |||||||||||
| 72 | 2 | ▶ | sub set_json { | ||||||||
|
Subroutine
set_json: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 73 | 2 | my $self = shift; | |||||||||
| 74 | 2 | my $name = shift; | |||||||||
| 75 | 2 | my $val = shift; | |||||||||
| 76 | 2 | my $schema = $self->schema; | |||||||||
| 77 | 2 | my $obj = JSON->new->allow_nonref->decode($val); | |||||||||
| 78 | 2 | return $schema->resultset('SysInfo')->set($name, $obj); | |||||||||
| 79 | } | ||||||||||
| 80 | |||||||||||
| 81 | |||||||||||
| 82 | 2 | ▶ | sub get_json { | ||||||||
|
Subroutine
get_json: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||
| 83 | 2 | my $self = shift; | |||||||||
| 84 | 2 | my $schema = $self->schema; | |||||||||
| 85 | |||||||||||
| 86 | 2 | my $val = $schema->resultset('SysInfo')->get(@_); | |||||||||
| 87 | 2 | ▶ | return if !$val; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 88 | 2 | return JSON->new->allow_nonref->encode($val); | |||||||||
| 89 | } | ||||||||||
| 90 | |||||||||||
| 91 | |||||||||||
| 92 | 4 | 1; # End of OpusVL::SysParams | |||||||||
| 93 | |||||||||||
| 94 | __END__ | ||||||||||