406d013cbfb1167a0ae60f4c836885511033c3aa
[gruntmaster-data.git] / lib / Gruntmaster / App / Command / Set.pm
1 package Gruntmaster::App::Command::Set;
2
3 use 5.014000;
4 use warnings;
5
6 our $VERSION = '5999.000_004';
7
8 use Gruntmaster::App '-command';
9 use Gruntmaster::Data;
10
11 use File::Slurp qw/read_file/;
12
13 sub opt_spec {
14 ['file!', 'Use the contents of a file as value']
15 }
16
17 sub usage_desc { "%c [-cjpu] set id column value [column value ...]\n%c [-cjpu] set --file id column filename [column filename ...]" }
18
19 sub validate_args {
20 my ($self, $opt, $args) = @_;
21 my @args = @$args;
22 $self->usage_error('No table selected') unless $self->app->table;
23 $self->usage_error('Not enough arguments provided') if @args < 3;
24 $self->usage_error('The number of arguments must be odd') unless @args % 2;
25 }
26
27 sub execute {
28 my ($self, $opt, $args) = @_;
29 my ($id, %values) = @$args;
30 %values = map { $_ => scalar read_file $values{$_} } keys %values if $opt->{file};
31 db->update($self->app->table, \%values, {id => $id});
32 }
33
34 1;
35 __END__
36
37 =encoding utf-8
38
39 =head1 NAME
40
41 Gruntmaster::App::Command::Set - set a property of an object
42
43 =head1 SYNOPSIS
44
45 gm -u set MGV name 'Marius Gavrilescu'
46 gm -p set aplusb level beginner
47 gm -c set test_ct 'This is a <b>test</b> contest.<br>Nothing to see here'
48 gm -j set 100 result_text Accepted
49
50 =head1 DESCRIPTION
51
52 The set command takes three arguments: an object id, a property name,
53 and a value. It sets the given property of the given object to the
54 given value.
55
56 =head1 SEE ALSO
57
58 L<gm>
59
60 =head1 AUTHOR
61
62 Marius Gavrilescu, E<lt>marius@ieval.roE<gt>
63
64 =head1 COPYRIGHT AND LICENSE
65
66 Copyright (C) 2015 by Marius Gavrilescu
67
68 This library is free software; you can redistribute it and/or modify
69 it under the same terms as Perl itself, either Perl version 5.20.1 or,
70 at your option, any later version of Perl 5 you may have available.
71
72
73 =cut
This page took 0.024482 seconds and 3 git commands to generate.