Add name to Ordered
Leon Timmermans
1 year, 5 months ago
240 | 240 | } |
241 | 241 | |
242 | 242 | class Ordered { |
243 | has Str:D $.name = 'some'; | |
243 | 244 | has Any:U $.type = Str; |
244 | 245 | has Code:D $.converter = get-converter($!type); |
245 | 246 | method type-name() { |
358 | 359 | sub make-positional($type, $name) { |
359 | 360 | CATCH { when ConverterInvalid { .rethrow-with($name); }} |
360 | 361 | my $converter = get-converter($type); |
361 | return Ordered.new(:$type, :$converter); | |
362 | return Ordered.new(:$name, :$type, :$converter); | |
362 | 363 | } |
363 | 364 | |
364 | 365 | my Str @ordinals = <first second third fourth fifth sixth seventh eighth nineth tenth some some> ... *; |
422 | 423 | } |
423 | 424 | multi sub trait_mod:<is>(Parameter $param where $param.positional, Str:D :$option!) is export(:DEFAULT, :traits) { |
424 | 425 | 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))); | |
426 | 427 | return $param does Formatted::Positional($argument); |
427 | 428 | } |
428 | 429 | 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); | |
430 | 431 | return $param does Formatted::Positional($argument); |
431 | 432 | } |
432 | 433 | |
493 | 494 | |
494 | 495 | sub merge-positional-object(@positionals-for, $elems) { |
495 | 496 | 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; | |
497 | 498 | return @positionals[0]; |
498 | 499 | } |
499 | 500 | |
628 | 629 | |
629 | 630 | my &fallback-converter = $compat-positional ?? &val !! *.self; |
630 | 631 | 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 | } | |
634 | 639 | }; |
635 | 640 | |
636 | 641 | @$write-args = @list if $write-args; |