| 1 | # You may distribute under the terms of either the GNU General Public License | ||
| 2 | # or the Artistic License (the same terms as Perl itself) | ||
| 3 | # | ||
| 4 | # (C) Paul Evans, 2021-2024 -- leonerd@leonerd.org.uk | ||
| 5 | |||
| 6 | package Commandable::Finder::SubAttributes::Attrs 0.14; | ||
| 7 | |||
| 8 | use v5.26; | ||
| 9 | use warnings; | ||
| 10 | # We can't use 'signatures' feature here because the order of attributes vs. | ||
| 11 | # signature changed in perl 5.28. The syntax we want to use only works on 5.28 | ||
| 12 | # onwards but it would be nice to still support 5.26 for a while longer. | ||
| 13 | |||
| 14 | use Carp; | ||
| 15 | use meta 0.003_003; | ||
| 16 | no warnings qw( meta::experimental ); | ||
| 17 | |||
| 18 | use Attribute::Storage 0.12; | ||
| 19 | |||
| 20 | =head1 NAME | ||
| 21 | |||
| 22 | C<Commandable::Finder::SubAttributes::Attrs> - subroutine attribute definitions for C<Commandable::Finder::SubAttributes> | ||
| 23 | |||
| 24 | =head1 DESCRIPTION | ||
| 25 | |||
| 26 | This module contains the attribute definitions to apply to subroutines when | ||
| 27 | using L<Commandable::Finder::SubAttributes>. It should not be used directly. | ||
| 28 | |||
| 29 | =cut | ||
| 30 | |||
| 31 | sub import_into | ||
| 32 | { | ||
| 33 | my ( $pkg, $caller ) = @_; | ||
| 34 | # Importing these lexically is a bit of a mess. | ||
| 35 | my $callermeta = meta::package->get( $caller ); | ||
| 36 | |||
| 37 | $callermeta->add_symbol( '&MODIFY_CODE_ATTRIBUTES' => \&MODIFY_CODE_ATTRIBUTES ); | ||
| 38 | push $callermeta->get_or_add_symbol( '@ISA' )->reference->@*, __PACKAGE__; | ||
| 39 | } | ||
| 40 | |||
| 41 | sub Command_description :ATTR(CODE) | ||
| 42 | { | ||
| 43 | my ( $class, $text ) = @_; | ||
| 44 | return $text; | ||
| 45 | } | ||
| 46 | |||
| 47 | sub Command_arg :ATTR(CODE,MULTI) | ||
| 48 | { | ||
| 49 | my ( $class, $args, $name, $description ) = @_; | ||
| 50 | my $optional = $name =~ s/\?$//; | ||
| 51 | my $slurpy = $name =~ s/\.\.\.$//; | ||
| 52 | |||
| 53 | my %arg = ( | ||
| 54 | name => $name, | ||
| 55 | description => $description, | ||
| 56 | optional => $optional, | ||
| 57 | slurpy => $slurpy, | ||
| 58 | # TODO: all sorts involving type, etc... | ||
| 59 | ); | ||
| 60 | |||
| 61 | push @$args, \%arg; | ||
| 62 | |||
| 63 | return $args; | ||
| 64 | } | ||
| 65 | |||
| 66 | sub Command_opt :ATTR(CODE,MULTI) | ||
| 67 | { | ||
| 68 | my ( $class, $opts, $name, $description, $default ) = @_; | ||
| 69 | my $mode = "set"; | ||
| 70 | $mode = "value" if $name =~ s/=$//; | ||
| 71 | $mode = "inc" if $name =~ s/\+$//; | ||
| 72 | |||
| 73 | my $negatable = $name =~ s/\!$//; | ||
| 74 | my $multi = $name =~ s/\@$//; | ||
| 75 | |||
| 76 | my %optspec = ( | ||
| 77 | name => $name, | ||
| 78 | description => $description, | ||
| 79 | mode => $mode, | ||
| 80 | multi => $multi, | ||
| 81 | negatable => $negatable, | ||
| 82 | default => $default, | ||
| 83 | ); | ||
| 84 | |||
| 85 | push @$opts, \%optspec; | ||
| 86 | |||
| 87 | return $opts; | ||
| 88 | } | ||
| 89 | |||
| 90 | sub GlobalOption :ATTR(SCALAR) | ||
| 91 | { | ||
| 92 | my ( $class, $name, $description ) = @_; | ||
| 93 | return [ $name, $description ]; | ||
| 94 | } | ||
| 95 | |||
| 96 | =head1 AUTHOR | ||
| 97 | |||
| 98 | Paul Evans <leonerd@leonerd.org.uk> | ||
| 99 | |||
| 100 | =cut | ||
| 101 | |||
| 102 | 0x55AA; |