blib/lib/UR/Namespace/Command/Init.pm untested

filter: Statementstmt 0.0% 0 / 32 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 13 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 5 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 54 SCAR 17.9
CC
2
Cov
0%
execute
6.0
sub_command_sort_position
2.0
BEGIN
2.0
CRAP 6.0
1 package UR::Namespace::Command::Init;
2 use strict;
3 use warnings;
4 use UR;
5 our $VERSION = "0.46"; # UR $VERSION;
6  
7 UR::Object::Type->define(
8 class_name => __PACKAGE__,
9 is => "Command",
10 has => [
11 namespace => {
12 is => 'Text',
13 shell_args_position => 1,
14 doc => 'the name of the namespace/app to create'
15 },
16 db => {
17 is => 'Text',
18 is_optional => 1,
19 shell_args_position => 2,
20 doc => 'the (optional) DBI connection string for the primary data source',
21 },
22 ],
23 doc => 'create a new ur app with default classes in place',
24 );
25  
26 sub sub_command_sort_position { 1 }
27  
28 sub execute {
29 my $self = shift;
30 my $c;
31 my $t = UR::Context::Transaction->begin();
32  
33 $self->status_message("*** ur define namespace " . $self->namespace);
34 UR::Namespace::Command::Define::Namespace->execute(nsname => $self->namespace)->result or die;
35  
36 if ($self->db) {
37 $self->status_message("\n*** cd " . $self->namespace);
38 chdir $self->namespace or ($self->error_message("error changing to namespace dir? $!") and die);
39
40 $self->status_message("\n*** ur define db " . $self->db);
41 $c = UR::Namespace::Command::Define::Db->create(uri => $self->db) or return;
42 $c->dump_status_messages(1);
43 $c->execute() or die;
44  
45 $self->status_message("\n*** ur update classes-from-db");
46 $c = UR::Namespace::Command::Update::ClassesFromDb->create();
47 $c->dump_status_messages(1);
48 $c->execute() or die;
49 }
50 else {
51 $self->status_message("next: cd " . $self->namespace);
52 $self->status_message("then: ur define db DSN");
53 $self->status_message("then: ur update classes-from-db");
54 }
55 $t->commit;
56  
57 return 1;
58 }
59  
60 1;
61