| 1 | package UR::Namespace::Command::Old::ExportDbicClasses; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | use UR; | ||
| 6 | our $VERSION = "0.46"; # UR $VERSION; | ||
| 7 | |||
| 8 | UR::Object::Type->define( | ||
| 9 | class_name => __PACKAGE__, | ||
| 10 | is => 'UR::Namespace::Command::RunsOnModulesInTree', | ||
| 11 | has => [ | ||
| 12 | bare_args => { | ||
| 13 | is_optional => 1, | ||
| 14 | is_many => 1, | ||
| 15 | shell_args_position => 1 | ||
| 16 | } | ||
| 17 | ] | ||
| 18 | ); | ||
| 19 | |||
| 20 | sub help_brief { | ||
| 21 | "Create or update a DBIx::Class class from an already existing UR class"; | ||
| 22 | } | ||
| 23 | |||
| 24 | sub help_detail { | ||
| 25 | return <<EOS; | ||
| 26 | |||
| 27 | Given one or more UR class names on the command line, this will create | ||
| 28 | or update a DBIx::Class class. The files will appear under the DBIx directory | ||
| 29 | in the namespace. | ||
| 30 | |||
| 31 | EOS | ||
| 32 | } | ||
| 33 | |||
| 34 | |||
| 35 | |||
| 36 | sub x_execute { | ||
| 37 | my $self = shift; | ||
| 38 | my $params = shift; | ||
| 39 | |||
| 40 | #$DB::single = 1; | ||
| 41 | unless ($self->bare_args) { | ||
| 42 | $self->error_message("No class names were specified on the command line"); | ||
| 43 | $self->status_message($self->help_usage_complete_text,"\n"); | ||
| 44 | return; | ||
| 45 | } | ||
| 46 | |||
| 47 | my $namespace = $self->namespace_name; | ||
| 48 | unless ($namespace) { | ||
| 49 | $self->error_message("This command must be run from a namespace directory."); | ||
| 50 | return; | ||
| 51 | } | ||
| 52 | |||
| 53 | eval "use $namespace"; | ||
| 54 | if ($@) { | ||
| 55 | $self->error_message("Failed to load namespace $namespace"); | ||
| 56 | return; | ||
| 57 | } | ||
| 58 | |||
| 59 | foreach my $class_name ( $self->bare_args ) { | ||
| 60 | my $class = UR::Object::Type->get(class_name => $class_name); | ||
| 61 | |||
| 62 | unless ($class) { | ||
| 63 | $self->error_message("Couldn't load class metadata for $class_name"); | ||
| 64 | next; | ||
| 65 | } | ||
| 66 | |||
| 67 | $class->dbic_rewrite_module_header(); | ||
| 68 | } | ||
| 69 | return 1; | ||
| 70 | } | ||
| 71 | |||
| 72 | |||
| 73 | sub for_each_class_object { | ||
| 74 | my($self,$class) = @_; | ||
| 75 | |||
| 76 | return 1 unless ($class->table_name); # Skip classes without tables | ||
| 77 | |||
| 78 | $class->dbic_rewrite_module_header(); | ||
| 79 | return 1; | ||
| 80 | } | ||
| 81 | |||
| 82 | |||
| 83 | 1; | ||
| 84 |