line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package UR::Object::Command::Create; |
2
|
|
|
|
|
|
|
|
3
|
11
|
|
|
11
|
|
4755
|
use strict; |
|
11
|
|
|
|
|
32
|
|
|
11
|
|
|
|
|
324
|
|
4
|
11
|
|
|
11
|
|
62
|
use warnings; |
|
11
|
|
|
|
|
122
|
|
|
11
|
|
|
|
|
304
|
|
5
|
|
|
|
|
|
|
|
6
|
11
|
|
|
11
|
|
3114
|
use YAML; |
|
11
|
|
|
|
|
59413
|
|
|
11
|
|
|
|
|
3518
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
class UR::Object::Command::Create { |
9
|
|
|
|
|
|
|
is => 'Command::V2', |
10
|
|
|
|
|
|
|
is_abstract => 1, |
11
|
|
|
|
|
|
|
has_constant => { |
12
|
|
|
|
|
|
|
target_class => { via => 'namespace', to => 'target_class', }, |
13
|
|
|
|
|
|
|
}, |
14
|
|
|
|
|
|
|
doc => 'CRUD create command class.', |
15
|
|
|
|
|
|
|
}; |
16
|
|
|
|
|
|
|
|
17
|
0
|
|
|
0
|
0
|
0
|
sub help_brief { $_[0]->__meta__->doc } |
18
|
0
|
|
|
0
|
0
|
0
|
sub help_detail { $_[0]->__meta__->doc } |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub execute { |
21
|
1
|
|
|
1
|
|
58221
|
my $self = shift; |
22
|
|
|
|
|
|
|
|
23
|
1
|
|
|
|
|
3
|
my (%properties, %display_ids); |
24
|
1
|
|
|
|
|
2
|
for my $property_name ( @{$self->target_class_properties} ) { |
|
1
|
|
|
|
|
4
|
|
25
|
5
|
|
|
|
|
26
|
my @values = $self->$property_name; |
26
|
5
|
50
|
|
|
|
2391
|
next if not defined $values[0]; |
27
|
5
|
|
|
|
|
11
|
my $property = $self->__meta__->property_meta_for_name($property_name); |
28
|
5
|
100
|
|
|
|
61
|
if ( $property->is_many ) { |
29
|
1
|
|
|
|
|
8
|
$properties{$property_name} = \@values; |
30
|
1
|
|
|
|
|
2
|
$display_ids{$property_name} = [ map { UR::Object::Command::CrudUtil->display_id_for_value($_) } @values ]; |
|
1
|
|
|
|
|
14
|
|
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
else { |
33
|
4
|
|
|
|
|
22
|
$properties{$property_name} = $values[0]; |
34
|
4
|
|
|
|
|
9
|
$display_ids{$property_name} = UR::Object::Command::CrudUtil->display_id_for_value($values[0]); |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
1
|
|
|
|
|
16
|
$self->status_message("Params:"); |
39
|
1
|
|
|
|
|
1114
|
$self->status_message( YAML::Dump(\%display_ids) ); |
40
|
|
|
|
|
|
|
|
41
|
1
|
|
|
|
|
11501
|
my $tx = UR::Context::Transaction->begin; |
42
|
1
|
|
|
|
|
17391
|
my $target_class = $self->target_class; |
43
|
1
|
|
|
|
|
52
|
my $obj = $target_class->create(%properties); |
44
|
1
|
50
|
|
|
|
24396
|
$self->fatal_message('Create failed!') if not $obj; |
45
|
|
|
|
|
|
|
|
46
|
1
|
50
|
|
|
|
10
|
if (!$tx->commit ) { |
47
|
0
|
|
|
|
|
0
|
$tx->rollback; |
48
|
0
|
|
|
|
|
0
|
$self->fatal_message('Failed to commit software transaction!'); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
1
|
|
|
|
|
6161
|
$self->status_message("New\t%s\t%s", $obj->class, $obj->__display_name__); |
52
|
1
|
|
|
|
|
1378
|
1; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
1; |