File: ExportDbicClasses.pm

package info (click to toggle)
libur-perl 0.470%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 7,184 kB
  • sloc: perl: 61,813; javascript: 255; xml: 108; sh: 13; makefile: 9
file content (84 lines) | stat: -rw-r--r-- 1,831 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package UR::Namespace::Command::Old::ExportDbicClasses;

use strict;
use warnings;
use UR;
our $VERSION = "0.47"; # UR $VERSION;

UR::Object::Type->define(
    class_name => __PACKAGE__,
    is => 'UR::Namespace::Command::RunsOnModulesInTree',
    has => [
        bare_args => {
            is_optional => 1,
            is_many => 1,
            shell_args_position => 1
        }
    ]
);

sub help_brief {
    "Create or update a DBIx::Class class from an already existing UR class";
}

sub help_detail {
    return <<EOS;

Given one or more UR class names on the command line, this will create
or update a DBIx::Class class.  The files will appear under the DBIx directory
in the namespace.

EOS
}



sub x_execute {
    my $self = shift;
    my $params = shift;
    
#$DB::single = 1;
    unless ($self->bare_args) {
        $self->error_message("No class names were specified on the command line");
        $self->status_message($self->help_usage_complete_text,"\n");
        return;
    }

    my $namespace = $self->namespace_name;
    unless ($namespace) {
        $self->error_message("This command must be run from a namespace directory.");
        return;
    }

    eval "use $namespace";
    if ($@) {
        $self->error_message("Failed to load namespace $namespace");
        return;
    }

    foreach my $class_name ( $self->bare_args ) {
        my $class = UR::Object::Type->get(class_name => $class_name);

        unless ($class) {
            $self->error_message("Couldn't load class metadata for $class_name");
            next;
        }

        $class->dbic_rewrite_module_header();
    }
    return 1;
}


sub for_each_class_object {
    my($self,$class) = @_;

    return 1 unless ($class->table_name);  # Skip classes without tables

    $class->dbic_rewrite_module_header();
    return 1;
}


1;