| 1 | package OpusVL::SysParams::Schema::ResultSet::SysInfo; | ||||||||||
| 2 | |||||||||||
| 3 | 4 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 4 | extends 'DBIx::Class::ResultSet'; | |||||||||
| 5 | 4 | ▶ | use JSON; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | |||||||||||
| 8 | sub ordered | ||||||||||
| 9 | { | ||||||||||
| 10 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
ordered: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 11 | 0 | my $me = $self->current_source_alias; | |||||||||
| 12 | 0 | return $self->search(undef, { | |||||||||
| 13 | order_by => ["$me.label", "$me.name"], | ||||||||||
| 14 | }); | ||||||||||
| 15 | } | ||||||||||
| 16 | |||||||||||
| 17 | |||||||||||
| 18 | |||||||||||
| 19 | sub set | ||||||||||
| 20 | { | ||||||||||
| 21 | 9 | ▶ | my $self = shift; | ||||||||
|
Subroutine
set: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||
| 22 | 9 | my $name = shift; | |||||||||
| 23 | 9 | my $value = shift; | |||||||||
| 24 | 9 | my $data_type = shift; | |||||||||
| 25 | |||||||||||
| 26 | 9 | my $info = $self->find_or_new({ | |||||||||
| 27 | name => $name, | ||||||||||
| 28 | }); | ||||||||||
| 29 | |||||||||||
| 30 | 9 | $info->set_column(value => JSON->new->allow_nonref->encode($value)); | |||||||||
| 31 | 9 | ▶ | if ($data_type) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 32 | 2 | $info->set_column(data_type => $data_type); | |||||||||
| 33 | } | ||||||||||
| 34 | |||||||||||
| 35 | 9 | ▶ | if (! $info->data_type) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 36 | 5 | $info->set_type_from_value($value); | |||||||||
| 37 | } | ||||||||||
| 38 | |||||||||||
| 39 | 9 | $info->update_or_insert; | |||||||||
| 40 | |||||||||||
| 41 | 9 | return $value; | |||||||||
| 42 | } | ||||||||||
| 43 | |||||||||||
| 44 | sub get | ||||||||||
| 45 | { | ||||||||||
| 46 | 13 | ▶ | my $self = shift; | ||||||||
|
Subroutine
get: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 47 | 13 | my $name = shift; | |||||||||
| 48 | |||||||||||
| 49 | 13 | my $info = $self->find | |||||||||
| 50 | ({ | ||||||||||
| 51 | name => $name | ||||||||||
| 52 | }); | ||||||||||
| 53 | |||||||||||
| 54 | 13 | ▶ | return $info ? JSON->new->allow_nonref->decode($info->value) : undef; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 55 | } | ||||||||||
| 56 | |||||||||||
| 57 | sub del | ||||||||||
| 58 | { | ||||||||||
| 59 | 1 | ▶ | my $self = shift; | ||||||||
|
Subroutine
del: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||
| 60 | 1 | my $name = shift; | |||||||||
| 61 | |||||||||||
| 62 | 1 | my $info = $self->find | |||||||||
| 63 | ({ | ||||||||||
| 64 | name => $name | ||||||||||
| 65 | }); | ||||||||||
| 66 | |||||||||||
| 67 | 1 | ▶ | return $info ? $info->delete : undef; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 68 | } | ||||||||||
| 69 | |||||||||||
| 70 | sub key_names | ||||||||||
| 71 | { | ||||||||||
| 72 | 6 | ▶ | my $self = shift; | ||||||||
|
Subroutine
key_names: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 73 | |||||||||||
| 74 | 6 | return $self->search(undef, { order_by => 'name' })->get_column('name')->all; | |||||||||
| 75 | } | ||||||||||
| 76 | |||||||||||
| 77 | 4 | 1; | |||||||||
| 78 | |||||||||||
| 79 | __END__ | ||||||||||
| 80 | |||||||||||
| 81 | =pod | ||||||||||
| 82 | |||||||||||
| 83 | =encoding UTF-8 | ||||||||||
| 84 | |||||||||||
| 85 | =head1 NAME | ||||||||||
| 86 | |||||||||||
| 87 | OpusVL::SysParams::Schema::ResultSet::SysInfo | ||||||||||
| 88 | |||||||||||
| 89 | =head1 VERSION | ||||||||||
| 90 | |||||||||||
| 91 | version 0.18 | ||||||||||
| 92 | |||||||||||
| 93 | =head1 SYNOPSIS | ||||||||||
| 94 | |||||||||||
| 95 | This is the ResultSet that actually stores and gets results from DBIx::Class. | ||||||||||
| 96 | |||||||||||
| 97 | $schema->resultset('SysInfo')->set('test.param', 1); | ||||||||||
| 98 | $schema->resultset('SysInfo')->get('test.param'); | ||||||||||
| 99 | $schema->resultset('SysInfo')->del('test.param'); | ||||||||||
| 100 | |||||||||||
| 101 | This is used by the L<OpusVL::SysParams> object. | ||||||||||
| 102 | |||||||||||
| 103 | =head1 METHODS | ||||||||||
| 104 | |||||||||||
| 105 | =head2 get | ||||||||||
| 106 | |||||||||||
| 107 | Get a system parameter. The key name will only be meaningful if the same string | ||||||||||
| 108 | has already been provided to L</set> at some point in the past, or created via | ||||||||||
| 109 | the L<OpusVL::AppKitX::SysParams> interface. | ||||||||||
| 110 | |||||||||||
| 111 | =head2 set | ||||||||||
| 112 | |||||||||||
| 113 | =over | ||||||||||
| 114 | |||||||||||
| 115 | =item B<$name> | ||||||||||
| 116 | |||||||||||
| 117 | =item B<$value> | ||||||||||
| 118 | |||||||||||
| 119 | =item B<$data_type> | ||||||||||
| 120 | |||||||||||
| 121 | =back | ||||||||||
| 122 | |||||||||||
| 123 | Set a system parameter. The key name is simply a string. It's suggested you use some | ||||||||||
| 124 | kind of schema like 'system.key' to prevent name clashes with other unoriginal programmers. | ||||||||||
| 125 | |||||||||||
| 126 | The value and data type should correspond. A guess will be made, if you don't | ||||||||||
| 127 | provide the data type. Any value that can be JSON-encoded should work (i.e. no | ||||||||||
| 128 | CODE refs), but see L<OpusVL::SysParams::Schema::Result::SysInfo> for the list | ||||||||||
| 129 | of options for data type, and hence value type. | ||||||||||
| 130 | |||||||||||
| 131 | =head2 del | ||||||||||
| 132 | |||||||||||
| 133 | Delete a system parameter. | ||||||||||
| 134 | |||||||||||
| 135 | =head2 key_names | ||||||||||
| 136 | |||||||||||
| 137 | Returns the keys of the system parameters. | ||||||||||
| 138 | |||||||||||
| 139 | =head2 ordered | ||||||||||
| 140 | |||||||||||
| 141 | Returns a resultset with an ordering applied. | ||||||||||
| 142 | |||||||||||
| 143 | =head1 AUTHOR | ||||||||||
| 144 | |||||||||||
| 145 | OpusVL - www.opusvl.com | ||||||||||
| 146 | |||||||||||
| 147 | =head1 COPYRIGHT AND LICENSE | ||||||||||
| 148 | |||||||||||
| 149 | This software is copyright (c) 2011 - 2016 by OpusVL - www.opusvl.com. | ||||||||||
| 150 | |||||||||||
| 151 | This is free software; you can redistribute it and/or modify it under | ||||||||||
| 152 | the same terms as the Perl 5 programming language system itself. | ||||||||||
| 153 | |||||||||||
| 154 | =cut | ||||||||||