File Coverage

blib/lib/UR/Object/Command/Update.pm
Criterion Covered Total %
statement 23 25 92.0
branch 3 4 75.0
condition 3 3 100.0
subroutine 3 5 60.0
pod 0 2 0.0
total 32 39 82.0


line stmt bran cond sub pod time code
1             package UR::Object::Command::Update;
2              
3 11     11   7173 use strict;
  11         31  
  11         422  
4 11     11   76 use warnings 'FATAL';
  11         29  
  11         3674  
5              
6             class UR::Object::Command::Update {
7             is => 'Command::V2',
8             is_abstract => 1,
9             has_constant_transient => {
10             target_name_pl => { via => 'namespace', to => 'target_name_pl', },
11             target_name_ub_pl => { via => 'namespace', to => 'target_name_ub_pl', },
12             },
13             doc => 'CRUD update command class.',
14             };
15              
16 0     0 0 0 sub help_brief { $_[0]->__meta__->doc }
17 0     0 0 0 sub help_detail { $_[0]->__meta__->doc }
18              
19             sub execute {
20 5     5   332054 my $self = shift;
21              
22 5         23 my $new_value = $self->value;
23 5 50       51 $new_value = undef if $new_value eq '';
24 5         53 my $new_value_id = UR::Object::Command::CrudUtil->display_id_for_value($new_value);
25              
26 5         36 my $property_name = $self->property_name;
27 5         54 my $target_name_ub_pl = $self->target_name_ub_pl;
28 5         302 my @objects = $self->$target_name_ub_pl;
29              
30 5         15826 $self->status_message("Update %s %s...", $self->target_name_pl, $property_name);
31 5         4828 for my $obj( @objects ) {
32 5         41 my $old_value = $obj->$property_name;
33 5         7294 my $old_value_id = UR::Object::Command::CrudUtil->display_id_for_value($old_value);
34 5 100 100     27 if ( $self->only_if_null and defined $old_value ) {
35 2         29 $self->status_message("FAILED_NOT_NULL\t%s\t%s\t%s", $obj->class, $obj->id, $old_value_id);
36 2         1699 next;
37             }
38 3         42 $obj->$property_name($new_value);
39 3         11511 $self->status_message("UPDATE\t%s\t%s\t%s\t%s", $obj->class, $obj->id, $old_value_id, $new_value_id);
40             }
41 5         2373 1;
42             }
43              
44             1;