« blib/lib/Clustericious/Command/configure.pm
↑ Summary
blib/lib/Clustericious/Command/hypnotoad.pm »
| 1 | package Clustericious::Client::Meta::Route; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 40 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 40 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 40 | ▶ | use YAML::XS qw/LoadFile/; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 40 | ▶ | use DateTime::Format::DateParse; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 40 | ▶ | use Getopt::Long qw/GetOptionsFromArray/; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 40 | ▶ | use Mojo::Base qw/-base/; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 40 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 40 | ▶ | use Clustericious::Log; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 40 | ▶ | use Clustericious::Client::Meta; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | # ABSTRACT: metadata about a route' | ||||||||||||||||||||||||||||||||||||||||||
| 14 | 40 | our $VERSION = '1.29'; # VERSION | |||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | 40 | has 'client_class'; | |||||||||||||||||||||||||||||||||||||||||
| 18 | 40 | has 'route_name'; | |||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | 75 | ▶ | sub set { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | 75 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 23 | 75 | return Clustericious::Client::Meta->add_route_attribute( | |||||||||||||||||||||||||||||||||||||||||
| 24 | $self->client_class, $self->route_name, @_ ); | ||||||||||||||||||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | 49 | ▶ | sub get { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | 49 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 30 | 49 | return Clustericious::Client::Meta->get_route_attribute( | |||||||||||||||||||||||||||||||||||||||||
| 31 | $self->client_class, $self->route_name, @_ ); | ||||||||||||||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | 2 | ▶ | sub doc { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
doc: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 37 | 2 | return Clustericious::Client::Meta->get_route_doc( | |||||||||||||||||||||||||||||||||||||||||
| 38 | $self->client_class, $self->route_name, @_ | ||||||||||||||||||||||||||||||||||||||||||
| 39 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | 30 | ▶ | sub set_doc { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_doc: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | 30 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 45 | 30 | return Clustericious::Client::Meta->add_route( | |||||||||||||||||||||||||||||||||||||||||
| 46 | $self->client_class, $self->route_name, @_ | ||||||||||||||||||||||||||||||||||||||||||
| 47 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||
| 51 | 17 | ▶ | sub process_args { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
process_args: called CC=47 SCAR=39.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | 17 | my $meta = shift; | |||||||||||||||||||||||||||||||||||||||||
| 53 | 17 | my @args = @_; | |||||||||||||||||||||||||||||||||||||||||
| 54 | 17 | my $cli; | |||||||||||||||||||||||||||||||||||||||||
| 55 | 17 | ▶ | if (ref $args[0] eq 'HASH' && $args[0]{command_line}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $args[0] eq "HASH" and $args[0]{"command_line"}
MC/DC50%1/2
ref $args[0] eq "HASH" and $args[0]{"command_line"}
ref $args[0] eq "HASH"
$args[0]{"command_line"}
Truth table66%2/3
A and B
A= ref $args[0] eq "HASH"B= $args[0]{"command_line"}
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | 5 | $cli = 1; | |||||||||||||||||||||||||||||||||||||||||
| 57 | 5 | shift @args; | |||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||
| 59 | 17 | ▶ | my $route_args = $meta->get('args') or return @args; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 60 | 14 | ▶ | unless ($cli) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | # method call, modify @args so that getopt will work. | ||||||||||||||||||||||||||||||||||||||||||
| 62 | # Prepend a "--" for named params. | ||||||||||||||||||||||||||||||||||||||||||
| 63 | 9 | my %valid; | |||||||||||||||||||||||||||||||||||||||||
| 64 | 9 | for (@$route_args) { | |||||||||||||||||||||||||||||||||||||||||
| 65 | 29 | ▶ | next if $_->{positional}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | 17 | my @name = ( $_->{name} ); | |||||||||||||||||||||||||||||||||||||||||
| 67 | 17 | ▶ | if ($_->{alt}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | 2 | push @name, split '\|', $_->{alt}; | |||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||
| 70 | 17 | my $type = $_->{type}; | |||||||||||||||||||||||||||||||||||||||||
| 71 | 17 | $valid{$_} = $type for @name; | |||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||
| 73 | 9 | my @new; | |||||||||||||||||||||||||||||||||||||||||
| 74 | 9 | ▶ | while (my $in = shift @args) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | 25 | ▶ | if (exists($valid{$in})) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | 11 | push @new, "--$in"; | |||||||||||||||||||||||||||||||||||||||||
| 77 | 11 | ▶ | push @new, shift @args if @args && defined($valid{$in}) && length($valid{$in}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
@args and defined $valid{$in} and length $valid{$in}
@args and defined $valid{$in}
MC/DC0%0/3
@args and defined $valid{$in} and length $valid{$in}
@args
defined $valid{$in}
length $valid{$in}
Truth table25%1/4
A and B and C
A= @argsB= defined $valid{$in}C= length $valid{$in}
| |||||||||||||||||||||||||||||||||||||||||||
| 78 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 79 | 14 | push @new, $in; | |||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||
| 83 | 9 | @args = @new; | |||||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||
| 86 | 14 | ▶ | my %req = map { $_->{required} ? ($_->{name} => 1):() } @$route_args; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 87 | my @getopt = map { | ||||||||||||||||||||||||||||||||||||||||||
| 88 | 14 | $_->{name} | |||||||||||||||||||||||||||||||||||||||||
| 89 | .($_->{alt} ? "|$_->{alt}" : "") | ||||||||||||||||||||||||||||||||||||||||||
| 90 | 48 | ▶ | .($_->{type} || '') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$_->{'type'} || ''
MC/DC100%1/1
$_->{'type'} || ''
$_->{'type'}
Truth table100%2/2
A
A= $_->{'type'}
| |||||||||||||||||||||||||||||||||||||||||||
| 91 | } @$route_args; | ||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||
| 93 | my $doc = join "\n", "Valid options for '".$meta->route_name."' are :", | ||||||||||||||||||||||||||||||||||||||||||
| 94 | map { | ||||||||||||||||||||||||||||||||||||||||||
| 95 | 14 | ▶ | sprintf(' --%-20s%-15s%s', $_->{name}, $_->{required} ? 'required' : '', $_->{doc} || "" ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$_->{'doc'} || ''
MC/DC100%1/1
$_->{'doc'} || ''
$_->{'doc'}
Truth table100%2/2
A
A= $_->{'doc'}
| |||||||||||||||||||||||||||||||||||||||||||
| 96 | } @$route_args; | ||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||
| 98 | 14 | my %method_args; | |||||||||||||||||||||||||||||||||||||||||
| 99 | 14 | Getopt::Long::Configure(qw/pass_through/); # TODO use OO interface | |||||||||||||||||||||||||||||||||||||||||
| 100 | 14 | ▶ | GetOptionsFromArray(\@args, \%method_args, @getopt) or LOGDIE "Invalid options. $doc\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||
| 102 | # Check for positional args | ||||||||||||||||||||||||||||||||||||||||||
| 103 | 14 | for (@$route_args) { | |||||||||||||||||||||||||||||||||||||||||
| 104 | 48 | ▶ | next unless @args; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 105 | 20 | ▶ | my $spec = $_->{positional} or next; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 106 | 12 | my $name = $_->{name}; | |||||||||||||||||||||||||||||||||||||||||
| 107 | 12 | for ($spec) { | |||||||||||||||||||||||||||||||||||||||||
| 108 | 12 | ▶ | /one/ and do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 109 | 11 | $method_args{$name} = shift @args; | |||||||||||||||||||||||||||||||||||||||||
| 110 | 11 | next; | |||||||||||||||||||||||||||||||||||||||||
| 111 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 112 | 1 | ▶ | /many/ and do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 113 | 1 | ▶ | push @{ $method_args{$name} }, shift @args while @args; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 114 | 1 | next; | |||||||||||||||||||||||||||||||||||||||||
| 115 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | die "unknown positional spec : $spec"; | |||||||||||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||
| 120 | # Check for required args | ||||||||||||||||||||||||||||||||||||||||||
| 121 | 14 | for (@$route_args) { | |||||||||||||||||||||||||||||||||||||||||
| 122 | 41 | my $name = $_->{name}; | |||||||||||||||||||||||||||||||||||||||||
| 123 | 41 | ▶ | next unless $_->{required}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 124 | 7 | ▶ | next if exists($method_args{$name}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 125 | 2 | LOGDIE "Missing value for required argument '$name'\n$doc\n"; | |||||||||||||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||
| 128 | 12 | ▶ | LOGDIE "Unknown option : @args\n$doc\n" if @args; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||
| 130 | # Check for preprocessing of args | ||||||||||||||||||||||||||||||||||||||||||
| 131 | 12 | for (@$route_args) { | |||||||||||||||||||||||||||||||||||||||||
| 132 | 38 | my $name = $_->{name}; | |||||||||||||||||||||||||||||||||||||||||
| 133 | 38 | ▶ | next unless $_->{preprocess}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 134 | 4 | ▶ | LOGDIE "internal error: cannot handle $_->{preprocess}" unless $_->{preprocess} =~ /yamldoc|list|datetime/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 135 | 4 | ▶ | my $filename = $method_args{$name} or next; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 136 | 4 | ▶ | LOGDIE "Argument for $name should be a filename, an arrayref or - for STDIN" if $filename && $filename =~ /\n/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$filename and $filename =~ /\n/u
MC/DC0%0/2
$filename and $filename =~ /\n/u
$filename
$filename =~ /\n/u
Truth table33%1/3
A and B
A= $filenameB= $filename =~ /\n/u
| |||||||||||||||||||||||||||||||||||||||||||
| 137 | 4 | for ($_->{preprocess}) { | |||||||||||||||||||||||||||||||||||||||||
| 138 | 4 | ▶ | /yamldoc/ and do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 139 | 2 | ▶ | next if ref $filename; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 140 | 1 | ▶ | $method_args{$name} = ($filename eq "-" ? Load(join "",<STDIN>) : LoadFile($filename)) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 141 | or LOGDIE "Error parsing yaml in ($filename)"; | ||||||||||||||||||||||||||||||||||||||||||
| 142 | 1 | next; | |||||||||||||||||||||||||||||||||||||||||
| 143 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 144 | 2 | ▶ | /list/ and do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 145 | 2 | ▶ | next if ref $filename eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 146 | 1 | $method_args{$name} = [ map { chomp; $_ } IO::File->new("< $filename")->getlines ]; | |||||||||||||||||||||||||||||||||||||||||
| 147 | 1 | next; | |||||||||||||||||||||||||||||||||||||||||
| 148 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | ▶ | /^datetime$/ and do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | $method_args{$name} = DateTime::Format::DateParse->parse_datetime($method_args{$name})->iso8601(); | |||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||
| 152 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||
| 156 | # Order the args properly | ||||||||||||||||||||||||||||||||||||||||||
| 157 | 12 | my @method_args; | |||||||||||||||||||||||||||||||||||||||||
| 158 | 12 | for (@$route_args) { | |||||||||||||||||||||||||||||||||||||||||
| 159 | 38 | my $name = $_->{name}; | |||||||||||||||||||||||||||||||||||||||||
| 160 | 38 | ▶ | next unless exists($method_args{$name}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 161 | 29 | push @method_args, $name => $method_args{$name}; | |||||||||||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||||||||||||
| 163 | 12 | return @method_args; | |||||||||||||||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||
| 167 | 40 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||
| 169 | __END__ | ||||||||||||||||||||||||||||||||||||||||||