« blib/lib/UR/Namespace/Command/Test/Eval.pm
↑ Summary
blib/lib/UR/Object/Type/View/AvailableViews/Json.pm »
| 1 | |||
| 2 | package UR::Namespace::Command::Update::RewriteClassHeader; | ||
| 3 | |||
| 4 | use strict; | ||
| 5 | use warnings; | ||
| 6 | |||
| 7 | require UR; | ||
| 8 | our $VERSION = "0.46"; # UR $VERSION; | ||
| 9 | |||
| 10 | UR::Object::Type->define( | ||
| 11 | class_name => __PACKAGE__, | ||
| 12 | is => 'UR::Namespace::Command::RunsOnModulesInTree', | ||
| 13 | has => [ | ||
| 14 | force => { is => 'Boolean', is_optional => 1 }, | ||
| 15 | ] | ||
| 16 | ); | ||
| 17 | |||
| 18 | sub params_as_getopt_specification | ||
| 19 | { | ||
| 20 | my $self = shift; | ||
| 21 | my @spec = $self->SUPER::params_as_getopt_specification(@_); | ||
| 22 | return (@spec, "force!"); | ||
| 23 | } | ||
| 24 | |||
| 25 | sub help_brief | ||
| 26 | { | ||
| 27 | "Update::RewriteClassHeaders class descriptions headers to normalize manual changes." | ||
| 28 | } | ||
| 29 | |||
| 30 | sub help_detail | ||
| 31 | { | ||
| 32 | qq| | ||
| 33 | |||
| 34 | UR classes have a header at the top which defines the class in terms of its metadata. | ||
| 35 | This command replaces that text in the source module with a fresh copy. | ||
| 36 | |||
| 37 | It is most useful to fix formatting problems, since the data from which the new | ||
| 38 | version is made is the data supplied by the old version of the file. | ||
| 39 | |||
| 40 | It's somewhat of a "perltidy" for the module header. | ||
| 41 | |||
| 42 | | | ||
| 43 | } | ||
| 44 | |||
| 45 | sub for_each_class_object | ||
| 46 | { | ||
| 47 | #$DB::single = 1; | ||
| 48 | my $self = shift; | ||
| 49 | my $class = shift; | ||
| 50 | my $old = $class->module_header_source; | ||
| 51 | my $new = $class->resolve_module_header_source; | ||
| 52 | if ($self->force or ($old ne $new)) { | ||
| 53 | print "Updating:\t", $class->module_base_name, "\n"; | ||
| 54 | $class->rewrite_module_header and return 1; | ||
| 55 | |||
| 56 | print STDERR "Error rewriting header!" and return 0; | ||
| 57 | |||
| 58 | } | ||
| 59 | else { | ||
| 60 | #print $class->class_name . " has no source changes. " | ||
| 61 | # . "Ignoring " . $class->module_base_name . ".\n"; | ||
| 62 | return 1; | ||
| 63 | } | ||
| 64 | } | ||
| 65 | |||
| 66 | 1; | ||
| 67 | #$Header$ |