| 1 | package UR::Object::Property::View::DescriptionLineItem::Text; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | require UR; | ||
| 6 | our $VERSION = "0.46"; # UR $VERSION; | ||
| 7 | |||
| 8 | UR::Object::Type->define( | ||
| 9 | class_name => __PACKAGE__, | ||
| 10 | is => 'UR::Object::View::Default::Text', | ||
| 11 | doc => "View used by 'ur show properties' for each property line item", | ||
| 12 | ); | ||
| 13 | |||
| 14 | sub _update_view_from_subject { | ||
| 15 | my $self = shift; | ||
| 16 | |||
| 17 | my $property_meta = $self->subject; | ||
| 18 | return unless ($property_meta); | ||
| 19 | |||
| 20 | my $nullable = $property_meta->is_optional ? "NULLABLE" : ""; | ||
| 21 | |||
| 22 | my $column_name = $property_meta->column_name; | ||
| 23 | unless ($column_name) { | ||
| 24 | if ($property_meta->via) { | ||
| 25 | $column_name = $property_meta->via . '->' . $property_meta->to; | ||
| 26 | } elsif ($property_meta->is_classwide) { | ||
| 27 | $column_name = '(classwide)'; | ||
| 28 | |||
| 29 | } elsif ($property_meta->is_delegated) { | ||
| 30 | # delegated, but not via. Must be an object accessor | ||
| 31 | $column_name = '' | ||
| 32 | } elsif ($property_meta->is_calculated) { | ||
| 33 | my $calc_from = $property_meta->calculate_from; | ||
| 34 | if ($calc_from and @$calc_from) { | ||
| 35 | $column_name = '(calculated from ' . join(',',@$calc_from). ')'; | ||
| 36 | } else { | ||
| 37 | $column_name = '(calculated)'; | ||
| 38 | } | ||
| 39 | } else { | ||
| 40 | $column_name = '(no column)'; | ||
| 41 | } | ||
| 42 | } | ||
| 43 | |||
| 44 | my $data_type_string; | ||
| 45 | if (defined $property_meta->data_type) { | ||
| 46 | my $len = $property_meta->data_length; | ||
| 47 | $data_type_string = $property_meta->data_type . ( $len ? "(".$len.")" : ""); | ||
| 48 | } else { | ||
| 49 | $data_type_string = '(no type)'; | ||
| 50 | } | ||
| 51 | |||
| 52 | my $text = sprintf(" %2s %30s %-40s %25s $nullable", | ||
| 53 | $property_meta->is_id ? "ID" : " ", | ||
| 54 | $property_meta->property_name, | ||
| 55 | $column_name, | ||
| 56 | $data_type_string, | ||
| 57 | ); | ||
| 58 | |||
| 59 | my $widget = $self->widget(); | ||
| 60 | my $buffer_ref = $widget->[0]; | ||
| 61 | $$buffer_ref = $text; | ||
| 62 | return 1; | ||
| 63 | } | ||
| 64 | |||
| 65 | |||
| 66 | |||
| 67 | 1; | ||
| 68 | |||
| 69 | =pod | ||
| 70 | |||
| 71 | =head1 NAME | ||
| 72 | |||
| 73 | UR::Object::Property::View::DescriptionLineItem::Text - View class for UR::Object::Property | ||
| 74 | |||
| 75 | =head1 DESCRIPTION | ||
| 76 | |||
| 77 | Used by UR::Namespace::Command::Show::Properties when displaying information about a property | ||
| 78 | |||
| 79 | =cut |