Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

App::Cmd::Command and abstract encoding

by McA (Priest)
on Feb 28, 2013 at 09:13 UTC ( [id://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
McA

Replies are listed 'Best First'.
Re: App::Cmd::Command and abstract encoding
by tobyink (Canon) 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

      /^=encoding\s+[uU][tT][fF]-?8/
      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
      McA

      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

    Hi,

    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
    McA

    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

      Hi,

      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
      McA

        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?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1021027]
Approved by vinoth.ree
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (5)
As of 2024-03-19 03:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found