File Coverage

lib/UR/Namespace/Command/Define/Datasource.pm
Criterion Covered Total %
statement 30 35 85.7
branch 3 4 75.0
condition n/a
subroutine 6 8 75.0
pod 0 4 0.0
total 39 51 76.4


line stmt bran cond sub pod time code
1              
2             # The diff command delegates to sub-commands under the adjoining directory.
3              
4             package UR::Namespace::Command::Define::Datasource;
5              
6 2     2   813 use warnings;
  2         3  
  2         60  
7 2     2   6 use strict;
  2         3  
  2         30  
8 2     2   8 use UR;
  2         1  
  2         11  
9             our $VERSION = "0.46"; # UR $VERSION;
10              
11             UR::Object::Type->define(
12             class_name => __PACKAGE__,
13             is => "UR::Namespace::Command::Base",
14             has_optional => [
15             dsid => {
16             is => 'Text',
17             doc => "The full class name to give this data source.",
18             },
19             dsname => {
20             is => 'Text',
21             shell_args_position => 1,
22             doc => "The distinctive part of the class name for this data source. Will be prefixed with the namespace then '::DataSource::'.",
23             },
24             ],
25             doc => 'add a data source to the current namespace'
26             );
27              
28 0     0   0 sub _is_hidden_in_docs { 1 }
29              
30 0     0 0 0 sub sub_command_sort_position { 2 }
31              
32             sub data_source_module_pathname {
33 4     4 0 5 my $self = shift;
34              
35 4         31 my $ns_path = $self->namespace_path;
36              
37 4         23 my $dsid = $self->dsid;
38 4         19 my @ds_parts = split(/::/, $dsid);
39 4         4 shift @ds_parts; # Get rid of the namespace name
40              
41 4         11 my $filename = pop @ds_parts;
42 4         5 $filename .= '.pm';
43              
44 4         11 my $path = join('/', $ns_path, @ds_parts, $filename);
45 4         12 return $path;
46             }
47              
48             # Overriding these so one can be calculated from the other
49             sub dsid {
50 14     14 0 16 my $self = shift;
51              
52 14         40 my $dsid = $self->__dsid;
53 14 100       27 unless ($dsid) {
54 3         18 my $dsname = $self->__dsname;
55 3         16 my $namespace = $self->namespace_name;
56 3         10 $dsid = $namespace . '::DataSource::' . $dsname;
57 3         7 $self->__dsid($dsid);
58             }
59 14         20 return $dsid;
60             }
61              
62             sub dsname {
63 3     3 0 4 my $self = shift;
64              
65 3         9 my $dsname = $self->__dsname;
66 3 50       12 unless ($dsname) {
67 0         0 my $dsid = $self->__dsid;
68             # assumme the name is the last portion of the class name
69 0         0 $dsname = (split(/::/,$dsid))[-1];
70 0         0 $self->__dsname($dsname);
71             }
72 3         5 return $dsname;
73             }
74              
75              
76              
77             1;
78