blib/lib/UR/Namespace/Command/Update/RenameClass.pm untested

filter: Statementstmt 0.0% 0 / 41 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 56 SCAR 24.8
CC
3
Cov
0%
before
12.0
shell_args_description
2.0
help_description
2.0
CRAP 12.0
1  
2  
3 package UR::Namespace::Command::Update::RenameClass;
4  
5 use strict;
6 use warnings;
7 use UR;
8 our $VERSION = "0.46"; # UR $VERSION;
9  
10 UR::Object::Type->define(
11 class_name => __PACKAGE__,
12 is => "UR::Namespace::Command::Update::RewriteClassHeader",
13 );
14  
15 # Standard methods used to output help.
16  
17 sub shell_args_description {
18 "My::Old My::New";
19 }
20  
21 sub help_description {
22 "Updates class descriptions for to correspond with database schema changes."
23 }
24  
25 # Wrap execute since we take different parameters than a standard
26 # "runs on modules in tree" rewrite command.
27  
28 our $old;
29 our $new;
30  
31 sub execute {
32 my $self = shift;
33 $old = shift;
34 $new = shift;
35 $self->error_message("rename $old to $new not implemented");
36 return;
37 }
38  
39 # Override "before" to do the class editing.
40  
41 sub before {
42 my $self = shift;
43 my $class_objects = shift;
44
45 # By default, no classes are rewritten.
46 # As we find classes with the $old name, in their metadata,
47 # we add them to this list.
48 $class_objects = [];
49
50 print "finding properties which seem to refernce a class\n";
51 my @p = UR::Object::Property->is_loaded(
52 property_name => ["class_name","r_class_name","parent_class_name"]
53 );
54
55 print "found " . join("\n",map { $_->class_name . " -> " . $_->property_name } @_) . "\n";
56
57 print "checking instances of those properties\n";
58 my @changes;
59 for my $p (@p) {
60 my $class_name = $p->class_name;
61 my $property_name = $p->property_name;
62 my @obj = $class_name->is_loaded();
63 for my $obj (@obj) {
64 if ($obj->$property_name eq $new) {
65 Carp::confess("Name $new is already in use on $class_name, "
66 . $obj->{id}
67 . $property_name . "!"
68 );
69 }
70 elsif ($obj->$property_name eq $old) {
71 print "Setting $new in place of $old on $class_name, "
72 . $obj->{id}
73 . $property_name . ".\n";
74 push @changes, [$obj,$property_name,$new];
75 }
76 }
77 }
78
79 return 1;
80 }
81  
82 # we implement before() but use the default call to
83 # for_each_class_object() call in UR::Namespace::Command::rewrite
84  
85 1;
86