« blib/lib/UR/DataSource/RDBMS/TableColumn.pm
↑ Summary
blib/lib/UR/Namespace/Command/Define/Namespace.pm »
| 1 | |||
| 2 | # The diff command delegates to sub-commands under the adjoining directory. | ||
| 3 | |||
| 4 | package UR::Namespace::Command::Define::Datasource; | ||
| 5 | |||
| 6 | use warnings; | ||
| 7 | use strict; | ||
| 8 | use UR; | ||
| 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 | sub _is_hidden_in_docs { 1 } | ||
| 29 | |||
| 30 | sub sub_command_sort_position { 2 } | ||
| 31 | |||
| 32 | sub data_source_module_pathname { | ||
| 33 | my $self = shift; | ||
| 34 | |||
| 35 | my $ns_path = $self->namespace_path; | ||
| 36 | |||
| 37 | my $dsid = $self->dsid; | ||
| 38 | my @ds_parts = split(/::/, $dsid); | ||
| 39 | shift @ds_parts; # Get rid of the namespace name | ||
| 40 | |||
| 41 | my $filename = pop @ds_parts; | ||
| 42 | $filename .= '.pm'; | ||
| 43 | |||
| 44 | my $path = join('/', $ns_path, @ds_parts, $filename); | ||
| 45 | return $path; | ||
| 46 | } | ||
| 47 | |||
| 48 | # Overriding these so one can be calculated from the other | ||
| 49 | sub dsid { | ||
| 50 | my $self = shift; | ||
| 51 | |||
| 52 | my $dsid = $self->__dsid; | ||
| 53 | unless ($dsid) { | ||
| 54 | my $dsname = $self->__dsname; | ||
| 55 | my $namespace = $self->namespace_name; | ||
| 56 | $dsid = $namespace . '::DataSource::' . $dsname; | ||
| 57 | $self->__dsid($dsid); | ||
| 58 | } | ||
| 59 | return $dsid; | ||
| 60 | } | ||
| 61 | |||
| 62 | sub dsname { | ||
| 63 | my $self = shift; | ||
| 64 | |||
| 65 | my $dsname = $self->__dsname; | ||
| 66 | unless ($dsname) { | ||
| 67 | my $dsid = $self->__dsid; | ||
| 68 | # assumme the name is the last portion of the class name | ||
| 69 | $dsname = (split(/::/,$dsid))[-1]; | ||
| 70 | $self->__dsname($dsname); | ||
| 71 | } | ||
| 72 | return $dsname; | ||
| 73 | } | ||
| 74 | |||
| 75 | |||
| 76 | |||
| 77 | 1; | ||
| 78 |