Codebase list raku-getopt-long / 89d02fa
Add name to Ordered Leon Timmermans 1 year, 5 months ago
1 changed file(s) with 12 addition(s) and 7 deletion(s). Raw diff Collapse all Expand all
240240 }
241241
242242 class Ordered {
243 has Str:D $.name = 'some';
243244 has Any:U $.type = Str;
244245 has Code:D $.converter = get-converter($!type);
245246 method type-name() {
358359 sub make-positional($type, $name) {
359360 CATCH { when ConverterInvalid { .rethrow-with($name); }}
360361 my $converter = get-converter($type);
361 return Ordered.new(:$type, :$converter);
362 return Ordered.new(:$name, :$type, :$converter);
362363 }
363364
364365 my Str @ordinals = <first second third fourth fifth sixth seventh eighth nineth tenth some some> ... *;
422423 }
423424 multi sub trait_mod:<is>(Parameter $param where $param.positional, Str:D :$option!) is export(:DEFAULT, :traits) {
424425 CATCH { when ConverterInvalid { .rethrow-with("parameter $param.name()") }}
425 my $argument = Ordered.new(:type(type-for-format($option)));
426 my $argument = Ordered.new(:name($param.usage-name), :type(type-for-format($option)));
426427 return $param does Formatted::Positional($argument);
427428 }
428429 multi sub trait_mod:<is>(Parameter $param where $param.positional, Code:D :option($converter)!) is export(:DEFAULT, :traits) {
429 my $argument = Ordered.new(:type($param.type), :$converter);
430 my $argument = Ordered.new(:name($param.usage-name), :type($param.type), :$converter);
430431 return $param does Formatted::Positional($argument);
431432 }
432433
493494
494495 sub merge-positional-object(@positionals-for, $elems) {
495496 my @positionals = @positionals-for.grep(* > $elems)»[$elems];
496 die Exception.new("@ordinals[$elems].tc() arguments are of different types: { @positionals».type-name.join(', ') }") unless [eqv] @positionals;
497 die Exception.new("@ordinals[$elems].tc() arguments are of different types: { @positionals».type-name.join(', ') }") unless [eqv] @positionals».converter;
497498 return @positionals[0];
498499 }
499500
628629
629630 my &fallback-converter = $compat-positional ?? &val !! *.self;
630631 my @positionals = @list.kv.map: -> $index, $value {
631 CATCH { when ValueInvalid { .rethrow-with(@ordinals[$index]) }}
632 my $converter = @!positionals[$index] ?? @!positionals[$index].converter !! &fallback-converter;
633 convert($value, $converter);
632 with @!positionals[$index] -> $positional {
633 CATCH { when ValueInvalid { .rethrow-with($positional.name) }}
634 convert($value, $positional.converter);
635 } else {
636 CATCH { when ValueInvalid { .rethrow-with(@ordinals[$index]) }}
637 convert($value, &fallback-converter);
638 }
634639 };
635640
636641 @$write-args = @list if $write-args;