| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package UR::Namespace::Command::Define::Class; |
|
2
|
1
|
|
|
1
|
|
23
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
26
|
|
|
3
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
23
|
|
|
4
|
1
|
|
|
1
|
|
4
|
use UR; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
5
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = "0.46"; # UR $VERSION; |
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
class UR::Namespace::Command::Define::Class { |
|
8
|
|
|
|
|
|
|
is => 'UR::Namespace::Command::Base', |
|
9
|
|
|
|
|
|
|
has => [ |
|
10
|
|
|
|
|
|
|
names => { |
|
11
|
|
|
|
|
|
|
is_optional => 1, |
|
12
|
|
|
|
|
|
|
is_many => 1, |
|
13
|
|
|
|
|
|
|
shell_args_position => 1 |
|
14
|
|
|
|
|
|
|
}, |
|
15
|
|
|
|
|
|
|
extends => { doc => "The base class. Defaults to UR::Object.", default_value => 'UR::Object' }, |
|
16
|
|
|
|
|
|
|
], |
|
17
|
|
|
|
|
|
|
doc => 'Add one or more classes to the current namespace' |
|
18
|
|
|
|
|
|
|
}; |
|
19
|
|
|
|
|
|
|
|
|
20
|
0
|
|
|
0
|
0
|
|
sub sub_command_sort_position { 3 } |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub help_synopsis { |
|
23
|
|
|
|
|
|
|
return <<'EOS' |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
$ cd Acme |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
$ ur define class Animal Vegetable Mineral |
|
28
|
|
|
|
|
|
|
A Acme::Animal |
|
29
|
|
|
|
|
|
|
A Acme::Vegetable |
|
30
|
|
|
|
|
|
|
A Acme::Mineral |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
$ ur define class Dog Cat Bird --extends Animal |
|
33
|
|
|
|
|
|
|
A Acme::Dog |
|
34
|
|
|
|
|
|
|
A Acme::Cat |
|
35
|
|
|
|
|
|
|
A Acme::Bird |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
EOS |
|
38
|
0
|
|
|
0
|
0
|
|
} |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub execute { |
|
41
|
0
|
|
|
0
|
|
|
my $self = shift; |
|
42
|
0
|
|
|
|
|
|
my @class_names = $self->names; |
|
43
|
0
|
0
|
|
|
|
|
unless (@class_names) { |
|
44
|
0
|
|
|
|
|
|
$self->error_message("No class name(s) provided!"); |
|
45
|
0
|
|
|
|
|
|
return; |
|
46
|
|
|
|
|
|
|
} |
|
47
|
|
|
|
|
|
|
|
|
48
|
0
|
|
|
|
|
|
my $namespace = $self->namespace_name; |
|
49
|
0
|
|
0
|
|
|
|
my $is = $self->extends || 'UR::Object'; |
|
50
|
0
|
|
|
|
|
|
my $parent_class_meta = UR::Object::Type->get($is); |
|
51
|
0
|
0
|
|
|
|
|
unless ($parent_class_meta) { |
|
52
|
0
|
0
|
|
|
|
|
unless ($self->extends =~ /^${namespace}::/) { |
|
53
|
0
|
|
|
|
|
|
$parent_class_meta = UR::Object::Type->get($namespace . '::' . $is); |
|
54
|
0
|
0
|
|
|
|
|
if ($parent_class_meta) { |
|
55
|
0
|
|
|
|
|
|
$is = $namespace . '::' . $is; |
|
56
|
|
|
|
|
|
|
} |
|
57
|
|
|
|
|
|
|
} |
|
58
|
0
|
0
|
|
|
|
|
unless ($parent_class_meta) { |
|
59
|
0
|
|
|
|
|
|
$self->error_message("Failed to find base class $is!"); |
|
60
|
0
|
|
|
|
|
|
return; |
|
61
|
|
|
|
|
|
|
} |
|
62
|
|
|
|
|
|
|
} |
|
63
|
|
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
|
for my $class_name (@class_names) { |
|
65
|
0
|
0
|
|
|
|
|
unless ($class_name =~ /^${namespace}::/) { |
|
66
|
0
|
|
|
|
|
|
$class_name = $namespace . '::' . $class_name; |
|
67
|
|
|
|
|
|
|
} |
|
68
|
0
|
|
|
|
|
|
my $new_class = UR::Object::Type->create( |
|
69
|
|
|
|
|
|
|
class_name => $class_name, |
|
70
|
|
|
|
|
|
|
is => $is, |
|
71
|
|
|
|
|
|
|
); |
|
72
|
0
|
0
|
|
|
|
|
unless ($new_class) { |
|
73
|
0
|
|
|
|
|
|
$self->error_message("Failed to create class $class_name!: " |
|
74
|
|
|
|
|
|
|
. UR::Object::Type->error_message |
|
75
|
|
|
|
|
|
|
); |
|
76
|
0
|
|
|
|
|
|
return; |
|
77
|
|
|
|
|
|
|
} |
|
78
|
0
|
|
|
|
|
|
print "A $class_name\n"; |
|
79
|
0
|
0
|
|
|
|
|
$new_class->rewrite_module_header |
|
80
|
|
|
|
|
|
|
or die "Failed to write class $class_name!: " |
|
81
|
|
|
|
|
|
|
. $new_class->error_message; |
|
82
|
|
|
|
|
|
|
} |
|
83
|
0
|
|
|
|
|
|
return 1; |
|
84
|
|
|
|
|
|
|
} |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
1; |
|
87
|
|
|
|
|
|
|
|