blib/lib/UR/Object/View/Lister/Text.pm untested

filter: Statementstmt 0.0% 0 / 87 Branchbran 0.0% 0 / 20 Conditioncond 0.0% 0 / 8 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 128 SCAR 48.8
CC
11
Cov
0%
_update_view_from_subject
132.0
_update_subject_from_view
2.0
_add_aspect
2.0
CRAP 132.0
1 package UR::Object::View::Lister::Text;
2  
3 use strict;
4 use warnings;
5 require UR;
6 our $VERSION = "0.46"; # UR $VERSION;
7 use IO::File;
8  
9 UR::Object::Type->define(
10 class_name => __PACKAGE__,
11 is => 'UR::Object::View::Default::Text',
12 );
13  
14  
15 sub _update_view_from_subject {
16 my $self = shift;
17 my @changes = @_; # this is not currently resolved and passed-in
18
19 my $subject = $self->subject();
20 my $subject_class_meta = $subject->__meta__;
21 my @aspects = $self->aspects;
22
23 my %data_for_this_object;
24 my(%aspects_requiring_joins_by_name,%aspects_requiring_joins_by_via);
25 my %column_for_label;
26 for (my $i = 0; $i < @aspects; $i++) {
27 my $aspect = $aspects[$i];
28 my $label = $aspect->label;
29 my $aspect_name = $aspect->name;
30 $column_for_label{$label} = $i;
31  
32 my $property_meta = $subject_class_meta->property_meta_for_name($aspect_name);
33 if (my $via = $property_meta->via and $property_meta->is_many) {
34 $aspects_requiring_joins_by_name{$aspect_name} = $via;
35 $aspects_requiring_joins_by_via{$via} ||= [];
36 push @{$aspects_requiring_joins_by_via{$via}}, $aspect_name;
37 }
38  
39 if ($subject) {
40 my @value = $subject->$aspect_name;
41 if (@value == 1 and ref($value[0]) eq 'ARRAY') {
42 @value = @{$value[0]};
43 }
44
45 # Delegate to a subordinate view if need be
46 if ($aspect->delegate_view_id) {
47 my $delegate_view = $aspect->delegate_view;
48 foreach my $value ( @value ) {
49 $delegate_view->subject($value);
50 $delegate_view->_update_view_from_subject();
51 $value = $delegate_view->content();
52 }
53 }
54  
55 if (@value == 1) {
56 $data_for_this_object{$label} = $value[0];
57 } else {
58 $data_for_this_object{$label} = \@value;
59 }
60 }
61 }
62  
63 if (keys(%aspects_requiring_joins_by_via) > 1) {
64 $self->error_message("Viewing delegated properties via more than one property is not supported");
65 return;
66 }
67  
68 # fill in the first row of data
69 my @retval = ();
70 foreach my $aspect ( @aspects ) {
71 my $label = $aspect->label;
72 my $col = $column_for_label{$label};
73 if (ref($data_for_this_object{$label})) {
74 # it's a multi-value
75 $retval[0]->[$col] = shift @{$data_for_this_object{$label}};
76 } else {
77 $retval[0]->[$col] = $data_for_this_object{$label};
78 }
79 }
80  
81 foreach my $via ( keys %aspects_requiring_joins_by_via ) {
82
83 while(1) {
84 my @this_row;
85 foreach my $prop ( @{$aspects_requiring_joins_by_via{$via}} ) {
86 my $data;
87 if (ref($data_for_this_object{$prop}) eq 'ARRAY') {
88 $data = shift @{$data_for_this_object{$prop}};
89 next unless $data;
90 } else {
91 $data = $data_for_this_object{$prop};
92 $data_for_this_object{$prop} = [];
93 }
94 $this_row[$column_for_label{$prop}] = $data;
95 }
96 last unless @this_row;
97 push @retval, \@this_row;
98 }
99  
100 }
101  
102 foreach my $row ( @retval ) {
103 no warnings 'uninitialized';
104 $row = join("\t",@$row);
105 }
106  
107 my $text = join("\n", @retval);
108  
109 # The text widget won't print anything until show(),
110 # so store the data in the buffer for now
111 my $widget = $self->widget;
112 ${$widget->[0]} = $text; # Update the contents
113 return 1;
114 }
115  
116 sub _update_subject_from_view {
117 1;
118 }
119  
120 sub _add_aspect {
121 1;
122 }
123  
124 sub _remove_aspect {
125 1;
126 }
127  
128  
129 1;
130