Mercurial > repos > cpt > cpt_psm_comparison_table
comparison lib/CPT/ParameterGroup.pm @ 1:f093e08f21f3 draft default tip
planemo upload commit 94b0cd1fff0826c6db3e7dc0c91c0c5a8be8bb0c
| author | cpt |
|---|---|
| date | Mon, 05 Jun 2023 02:47:24 +0000 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 0:b8b8b52904a5 | 1:f093e08f21f3 |
|---|---|
| 1 package CPT::ParameterGroup; | |
| 2 use Moose; | |
| 3 use strict; | |
| 4 use warnings; | |
| 5 use autodie; | |
| 6 | |
| 7 # A special type of a ParameterCollection (could probably be a child...ohwell) | |
| 8 use Moose::Util::TypeConstraints; | |
| 9 #subtype 'TypeStr', as 'Str', where { $_ eq 'xor' || $_ eq 'or' || $_ eq 'and' }; | |
| 10 # Replaced with the enum | |
| 11 | |
| 12 has 'name' => ( is => 'rw', isa => 'Str'); | |
| 13 has 'description' => ( is => 'rw', isa => 'Str'); | |
| 14 has 'validator' => ( is => 'rw', isa => enum([qw(xor or and)])); | |
| 15 has 'options' => ( is => 'rw', isa => 'ArrayRef[HashRef]' ); | |
| 16 | |
| 17 | |
| 18 sub validate { | |
| 19 die 'Unimplemented'; | |
| 20 } | |
| 21 | |
| 22 | |
| 23 | |
| 24 sub set_data { | |
| 25 my ($self, $hash_ref) = @_; | |
| 26 my %d = %{$hash_ref}; | |
| 27 $self->name($d{name}); | |
| 28 $self->description($d{description}); | |
| 29 $self->validator($d{validator}); | |
| 30 $self->options($d{options}); | |
| 31 } | |
| 32 | |
| 33 | |
| 34 | |
| 35 sub getopt { | |
| 36 my ($self) = @_; | |
| 37 die 'unimplemented'; | |
| 38 } | |
| 39 | |
| 40 sub flattenOptionsArray{ | |
| 41 my ($self) = @_; | |
| 42 my @opts; | |
| 43 push(@opts, [sprintf("Option Group: %s\n%s\n[%s]", $self->name(), $self->description(), $self->_formatted_choice_str)]); | |
| 44 require CPT::ParameterCollection; | |
| 45 my $pC = CPT::ParameterCollection->new(); | |
| 46 foreach(@{$self->options()}){ | |
| 47 my %z = %{$_}; | |
| 48 my $group_name = $z{group}; | |
| 49 my @group_opts = @{$z{options}}; | |
| 50 push(@opts, [sprintf("Subgroup: %s", $group_name)]); | |
| 51 foreach(@group_opts){ | |
| 52 my $p = $pC->_coerce_param($_); | |
| 53 push(@opts, $p->getOptionsArray()); | |
| 54 } | |
| 55 } | |
| 56 return \@opts; | |
| 57 } | |
| 58 | |
| 59 sub _formatted_choice_str{ | |
| 60 my ($self) = @_; | |
| 61 if($self->validator() eq 'xor'){ | |
| 62 return 'Please only use options from ONE of the groups below, and no more'; | |
| 63 }elsif($self->validator() eq 'or'){ | |
| 64 return 'Please only use options from at least ONE of the groups below'; | |
| 65 }elsif($self->validator() eq 'and'){ | |
| 66 return 'Please ensure values/defaults are specified for ALL of the options in the groups below'; | |
| 67 } | |
| 68 return undef; | |
| 69 } | |
| 70 | |
| 71 | |
| 72 sub populate_from_getopt { | |
| 73 my ( $self, $opt ) = @_; | |
| 74 die 'unimplemented'; | |
| 75 } | |
| 76 | |
| 77 no Moose; | |
| 78 1; | |
| 79 | |
| 80 __END__ | |
| 81 | |
| 82 =pod | |
| 83 | |
| 84 =encoding UTF-8 | |
| 85 | |
| 86 =head1 NAME | |
| 87 | |
| 88 CPT::ParameterGroup | |
| 89 | |
| 90 =head1 VERSION | |
| 91 | |
| 92 version 1.99.4 | |
| 93 | |
| 94 =head2 validate | |
| 95 | |
| 96 $pC->validate(); | |
| 97 | |
| 98 calls the validate method, which loops through and checks that user values line up with the validate method in each and every slot. | |
| 99 | |
| 100 Currently unimplemented! | |
| 101 | |
| 102 =head2 getopt | |
| 103 | |
| 104 my @getopt_compatible_array = $pC->getopt() | |
| 105 | |
| 106 Returns a getopt compatible array by looping through the array and simply returning array objects, and calling the getOptionsArray method on CPT::Parameter::* objects | |
| 107 | |
| 108 =head2 populate_from_getopt | |
| 109 | |
| 110 $parameterCollection->populate_from_getopt($opt); | |
| 111 | |
| 112 Populate the ->value() from getopt. This is the special sauce of this portion of the module. | |
| 113 Our test case for this function is the connector choice problem. | |
| 114 | |
| 115 { | |
| 116 name => 'Data Source #1', | |
| 117 description => "FASTA data source for our script", | |
| 118 type => 'xor', # must select only from one subgroup | |
| 119 options => [ | |
| 120 { | |
| 121 group => 'Chado Custom', | |
| 122 options => [ | |
| 123 [ 'host' => 'Hostname', { required => 1, validate => 'Str' } ], | |
| 124 [ 'user' => 'Username', { required => 1, validate => 'Str' } ], | |
| 125 [ 'pass' => 'Password', { required => 1, validate => 'Str' } ], | |
| 126 [ 'name' => 'Database name', { required => 1, validate => 'Str' } ], | |
| 127 [ 'organism' => 'organism name', { required => 1, validate => 'Str' } ], | |
| 128 [ 'landmark' => 'landmark name', { required => 1, validate => 'Str' } ], | |
| 129 ] | |
| 130 }, | |
| 131 { | |
| 132 group => 'Chado GMOD pre-defined connector', | |
| 133 options => [ | |
| 134 [ 'conn=s' => 'Connection Nickname', { required => 1, validate => 'Str' } ], | |
| 135 ] | |
| 136 }, | |
| 137 { | |
| 138 group => 'File', | |
| 139 options => [ | |
| 140 [ 'file|f=' => 'Input file', { required => 1, validate => 'File/Input' } ], | |
| 141 ] | |
| 142 }, | |
| 143 | |
| 144 ] | |
| 145 }, | |
| 146 | |
| 147 This should intelligently set parameters in $opt based on the passed data. The real question is how to handle password.... | |
| 148 | |
| 149 =head1 AUTHOR | |
| 150 | |
| 151 Eric Rasche <rasche.eric@yandex.ru> | |
| 152 | |
| 153 =head1 COPYRIGHT AND LICENSE | |
| 154 | |
| 155 This software is Copyright (c) 2014 by Eric Rasche. | |
| 156 | |
| 157 This is free software, licensed under: | |
| 158 | |
| 159 The GNU General Public License, Version 3, June 2007 | |
| 160 | |
| 161 =cut |
