Make perlcritic happy
[gruntmaster-data.git] / lib / Gruntmaster / App / Command / Set.pm
CommitLineData
92f74061
MG
1package Gruntmaster::App::Command::Set;
2
3use 5.014000;
4use warnings;
5
6our $VERSION = '5999.000_004';
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
66Copyright (C) 2015 by Marius Gavrilescu
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.014744 seconds and 4 git commands to generate.