[Bps-public-commit] r13947 - in Prophet/trunk: . lib/Prophet/CLI/Command
sartak at bestpractical.com
sartak at bestpractical.com
Thu Jul 10 12:44:15 EDT 2008
Author: sartak
Date: Thu Jul 10 12:44:14 2008
New Revision: 13947
Modified:
Prophet/trunk/ (props changed)
Prophet/trunk/lib/Prophet/CLI/Command/Show.pm
Prophet/trunk/lib/Prophet/Record.pm
Log:
r64040 at onn: sartak | 2008-07-10 12:44:09 -0400
Add a show_props method to records, use it in the Show command. Also includes some basic formatting!
Modified: Prophet/trunk/lib/Prophet/CLI/Command/Show.pm
==============================================================================
--- Prophet/trunk/lib/Prophet/CLI/Command/Show.pm (original)
+++ Prophet/trunk/lib/Prophet/CLI/Command/Show.pm Thu Jul 10 12:44:14 2008
@@ -8,12 +8,7 @@
my $self = shift;
my $record = $self->_load_record;
- print "id: ".$record->luid." (" .$record->uuid.")\n";
- my $props = $record->get_props();
- for ( keys %$props ) {
- print $_. ": " . $props->{$_} . "\n";
- }
-
+ print $record->show_props;
}
__PACKAGE__->meta->make_immutable;
Modified: Prophet/trunk/lib/Prophet/Record.pm
==============================================================================
--- Prophet/trunk/lib/Prophet/Record.pm (original)
+++ Prophet/trunk/lib/Prophet/Record.pm Thu Jul 10 12:44:14 2008
@@ -364,6 +364,34 @@
return $luid;
}
+=head2 show_props
+
+Returns a stringified form of the properties suitable for displaying directly
+to the user. Also includes luid and uuid.
+
+=cut
+
+sub show_props {
+ my $self = shift;
+ my @fields;
+
+ push @fields, ["id", $self->luid ." (" . $self->uuid . ")"];
+ my $max_length = 2;
+
+ my $props = $self->get_props;
+ for (keys %$props) {
+ push @fields, [$_, $props->{$_}];
+ $max_length = length($_)
+ if length($_) > $max_length;
+ }
+
+ my $out = join "\n",
+ map { sprintf '%*s %s', -($max_length+1), "$_->[0]:", $_->[1] }
+ @fields;
+
+ return $out;
+}
+
__PACKAGE__->meta->make_immutable;
no Moose;
no MooseX::ClassAttribute;
More information about the Bps-public-commit
mailing list