Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

App::Cmd::Command and abstract encoding

by McA (Priest)
on Feb 28, 2013 at 09:13 UTC ( #1021027=perlquestion: print w/replies, xml ) Need Help??
McA has asked for the wisdom of the Perl Monks concerning the following question:

Hi all,

I just stumbled into a subtle problem with App::Cmd::Command:

The default behaviour of this module is to take an abstract from a #ABSTRACT comment in source code if it can't find something else. How can I tell it that my whole source file and therefore also the #ABSTRACT-line is UTF8-encoded?

I would like to avoid to write an extra abstract method to get around that problem.

Hints appreciated.

Best regards

Replies are listed 'Best First'.
Re: App::Cmd::Command and abstract encoding
by tobyink (Abbot) on Feb 28, 2013 at 09:25 UTC

    One would hope that...

    use utf8;

    ... would be sufficient, as that's how you tell Perl that some code is in UTF-8. It doesn't look like App::Cmd::Command pays heed to this though (see the abstract method defined therein).

    I'd argue that this is a bug.

    Personally I'd just do:

    use utf8; use constant abstract => q(go to the café);
    package Cow { use Moo; has name => (is => 'lazy', default => sub { 'Mooington' }) } say Cow->new->name

      Hi tobyink,

      thank you for the fast answer. Before checking whether someone answered here I had a look at the source code, too. So I had to smile reading your comment.

      I'm pretty sure it should be easy to react on a pattern

      while in status $inpod.

      It seems to be a little harder to parse for a use utf8;-like statement.

      What do you think about scanning for =encoding ?

      Best regards

      P.S.: I forgot something: I work with App::Cmd in combination with dzil and dzil generates the pod entries for me.

Re: App::Cmd::Command and abstract encoding
by McA (Priest) on Feb 28, 2013 at 10:19 UTC


    based on what I found in the source code and that I use a base class derived from App::Cmd::Command for all my commands I decided (constrained by time at the moment) to use the following solution:

    I wrote the following method in my Commands base class:

    sub abstract { my $self = shift; return decode('UTF-8', $self->SUPER::abstract(@_)); }

    Don't forget use Encode qw(decode);.

    Happy programming

    P.S.: Have I ever mentioned that I hate the whole encoding stuff... ;-)

Re: App::Cmd::Command and abstract encoding (=encoding utf8)
by Anonymous Monk on Feb 28, 2013 at 15:55 UTC
    perlpod/perlpodspec says use pod  =encoding encodingname directive, and Pod::Weaver should respect that, even though =encoding doesn't appear in the test suite


      you're completely right. I do use =encoding and I get the right output of perldoc MyPackage. But the method abstract of App::Cmd::Command doesn't respect it when scanning for an abstract message for showing as help text. That's why I wrote earlier that this method could scan for a pod line =encoding and try to respect the given encoding. Have a look at the source code.

      Best regards

        I asked rjbs on IRC and he said his preferred route was to just interpret all abstracts extracted from the source as being UTF-8, and forget about scanning for the encoding.

        I've offered to provide him with a patch, but if anyone beats me to it, that's just fine by me.

        package Cow { use Moo; has name => (is => 'lazy', default => sub { 'Mooington' }) } say Cow->new->name

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1021027]
Approved by vinoth.ree
Front-paged by Corion
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (14)
As of 2018-07-17 11:58 GMT
Find Nodes?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?

    Results (363 votes). Check out past polls.