From 74f288242dc5f9a8914b0f06807dbe373cae192c Mon Sep 17 00:00:00 2001 From: "Kobayasi, Hiroaki" Date: Wed, 12 Sep 2018 12:56:38 +0900 Subject: [PATCH] For [GH #49] - Add support for :Doc() code attribute. * Doc("...."), Doc('...'), Doc(bare string) are accepted. * Also doc() is accepted (but perl warns about future reserved word) --- Base/CLI.pm | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/Base/CLI.pm b/Base/CLI.pm index e929eab..97f3d0e 100644 --- a/Base/CLI.pm +++ b/Base/CLI.pm @@ -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'] @@ -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;