]> iEval git - gruntmaster-data.git/blame - lib/Gruntmaster/App/Command/Set.pm
Bump version and update Changes
[gruntmaster-data.git] / lib / Gruntmaster / App / Command / Set.pm
CommitLineData
92f74061
MG
1package Gruntmaster::App::Command::Set;
2
3use 5.014000;
4use warnings;
5
e1b6fd19 6our $VERSION = '5999.000_014';
92f74061
MG
7
8use Gruntmaster::App '-command';
9use Gruntmaster::Data;
10
11use File::Slurp qw/read_file/;
12
13sub opt_spec {
dcf7f640 14 ['file!', 'Use the contents of a file as value']
92f74061
MG
15}
16
17sub usage_desc { "%c [-cjpu] set id column value [column value ...]\n%c [-cjpu] set --file id column filename [column filename ...]" }
18
19sub 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
27sub 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
341;
35__END__
63afa40a
MG
36
37=encoding utf-8
38
39=head1 NAME
40
41Gruntmaster::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
52The set command takes three arguments: an object id, a property name,
53and a value. It sets the given property of the given object to the
54given value.
55
56=head1 SEE ALSO
57
58L<gm>
59
60=head1 AUTHOR
61
62Marius Gavrilescu, E<lt>marius@ieval.roE<gt>
63
64=head1 COPYRIGHT AND LICENSE
65
e1b9f3dd 66Copyright (C) 2014-2015 by Marius Gavrilescu
63afa40a
MG
67
68This library is free software; you can redistribute it and/or modify
69it under the same terms as Perl itself, either Perl version 5.20.1 or,
70at your option, any later version of Perl 5 you may have available.
71
72
73=cut
This page took 0.031416 seconds and 4 git commands to generate.