/usr/share/perl5/Prophet/CLI/Command/Show.pm is in libprophet-perl 0.750-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 | package Prophet::CLI::Command::Show;
use Any::Moose;
use Params::Validate;
extends 'Prophet::CLI::Command';
with 'Prophet::CLI::RecordCommand';
sub ARG_TRANSLATIONS { shift->SUPER::ARG_TRANSLATIONS(), 'b' => 'batch' };
sub usage_msg {
my $self = shift;
my ($cmd, $type_and_subcmd) = $self->get_cmd_and_subcmd_names;
return <<"END_USAGE";
usage: ${cmd}$type_and_subcmd <record-id> [--batch] [--verbose]
END_USAGE
}
sub run {
my $self = shift;
$self->print_usage if $self->has_arg('h');
$self->require_uuid;
my $record = $self->_load_record;
print $self->stringify_props(
record => $record,
batch => $self->has_arg('batch'),
verbose => $self->has_arg('verbose'),
);
}
=head2 stringify_props
Returns a stringified form of the properties suitable for displaying directly
to the user. Also includes luid and uuid.
=cut
sub stringify_props {
my $self = shift;
my %args = validate( @_, {record => { ISA => 'Prophet::Record'},
batch => 1,
verbose => 1});
my $record = $args{'record'};
my $props = $record->get_props;
# which props are we going to display?
my @show_props;
if ($record->can('props_to_show')) {
@show_props = $record->props_to_show(\%args);
# if they ask for verbosity, then display all the other fields
# after the fields that our subclass wants to show
if ($args{verbose}) {
my %already_shown = map { $_ => 1 } @show_props;
push @show_props, grep { !$already_shown{$_} }
sort keys %$props;
}
}
else {
@show_props = ('id', sort keys %$props);
}
# kind of ugly but it simplifies the code
$props->{id} = $record->luid ." (" . $record->uuid . ")";
my @fields;
for my $field (@show_props) {
my $value = $props->{$field};
# don't bother displaying unset fields
next if !defined($value);
push @fields, [$field, $value];
}
return join '',
map {
my ($field, $value) = @$_;
$self->format_prop(@$_);
}
@fields;
}
sub format_prop {
my $self = shift;
my $field = shift;
my $value = shift;
return "$field: $value\n"
}
__PACKAGE__->meta->make_immutable;
no Any::Moose;
1;
|