[Bps-public-commit] r13968 - in Prophet/trunk: . lib/Prophet/CLI/Command
sartak at bestpractical.com
sartak at bestpractical.com
Thu Jul 10 17:05:01 EDT 2008
Author: sartak
Date: Thu Jul 10 17:05:01 2008
New Revision: 13968
Modified:
Prophet/trunk/ (props changed)
Prophet/trunk/lib/Prophet/CLI/Command/Show.pm
Prophet/trunk/lib/Prophet/Record.pm
Log:
r64078 at onn: sartak | 2008-07-10 16:45:23 -0400
Allow subclasses of Prophet::Record to define an which properties will be displayed (and in what order)
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 17:05:01 2008
@@ -8,7 +8,7 @@
my $self = shift;
my $record = $self->_load_record;
- print $record->show_props(batch => $self->has_arg('batch'));
+ print $record->stringify_props(batch => $self->has_arg('batch'));
}
__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 17:05:01 2008
@@ -377,16 +377,29 @@
=cut
-sub show_props {
+sub stringify_props {
my $self = shift;
my %args = @_;
- my @fields;
+ my $props = $self->get_props;
+
+ # kind of ugly but it simplifies the code
+ $props->{id} = $self->luid ." (" . $self->uuid . ")";
+
+ # which props are we going to display?
+ my @show_props;
+ if ($self->can('props_to_show')) {
+ @show_props = $self->props_to_show(\%args);
+ }
+ else {
+ @show_props = keys %$props;
+ }
+
my $max_length = 0;
+ my @fields;
- # add a property to @fields
- my $add_prop = sub {
- my ($field, $value) = @_;
+ for my $field (@show_props) {
+ my $value = $props->{$field};
# color if we can (and should)
my ($color_field, $color_value) = ($field, $value);
@@ -406,13 +419,6 @@
# length but we only care about display length
$max_length = length($field)
if length($field) > $max_length;
- };
-
- $add_prop->("id" => $self->luid ." (" . $self->uuid . ")");
-
- my $props = $self->get_props;
- for (keys %$props) {
- $add_prop->($_ => $props->{$_});
}
$max_length = 0 if $args{batch};
More information about the Bps-public-commit
mailing list