Skip to content

Commit

Permalink
For [GH #49] - Add support for :Doc() code attribute.
Browse files Browse the repository at this point in the history
* Doc("...."), Doc('...'), Doc(bare string) are accepted.
* Also doc() is accepted (but perl warns about future reserved word)
  • Loading branch information
hkoba committed Sep 12, 2018
1 parent f5b3473 commit 74f2882
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions Base/CLI.pm
Expand Up @@ -6,6 +6,8 @@ use mro qw/c3/;
use File::Basename ();
use Data::Dumper ();

use attributes ();

use MOP4Import::Base::Configure -as_base, qw/FieldSpec/
, [fields =>
[quiet => doc => 'to be (somewhat) quiet']
Expand Down Expand Up @@ -163,4 +165,25 @@ sub cli_format_option {
sprintf " --%-${len}s %s\n", $fs->{name}, $fs->{doc} // "";
}

# Poorman's code attribute handler, only for Doc().
{
my %cmd_doc;

sub MODIFY_CODE_ATTRIBUTES {
my ($pack, $sub, @attrs) = @_;
map {
my $cp = $_;
if ($cp =~ s/^Doc\(//i) {
$cp =~ s/\)$//;
$cp =~ s/^\"(.*?)\"$/$1/s;
$cp =~ s/^\'(.*?)\'$/$1/s;
$cmd_doc{$sub} = $cp;
();
} else {
$_;
}
} @attrs;
}
}

1;

0 comments on commit 74f2882

Please sign in to comment.