Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

use utf8 pragma with moo

by AlexP (Pilgrim)
on Jan 14, 2022 at 17:31 UTC ( [id://11140453]=perlquestion: print w/replies, xml ) Need Help??

AlexP has asked for the wisdom of the Perl Monks concerning the following question:

Hi monks!
I decided to dive into Moo and found that it's not necessary to use pragmas 'strict and warnings', cause they are already enabled by Moo.
But I couldn't find any information about utf8 pragma. Do I need to use it explicit?

And there is one more question about use namespace::clean and no warnings qw(experimental::signatures). In Moo docs there is a line: "Moo will not clean up imported subroutines for you; you will have to do that manually. The recommended way to do this is to declare your imports first, then use Moo, then use namespace::clean" . But when I do this warning about signatures occurs. Is there a nicer way to use them together?

Replies are listed 'Best First'.
Re: use utf8 pragma with moo
by davido (Cardinal) on Jan 14, 2022 at 18:45 UTC

    Within your Moo based module, try this:

    package Foo; use Moo; use Data::Dumper; warn Dumper [sort keys %INC]; 1;

    On my system with Perl 5.32 I get the following output:

    $VAR1 = [ 'Carp.pm', 'Config.pm', 'Data/Dumper.pm', 'Exporter.pm', 'Foo.pm', 'List/Util.pm', 'Moo.pm', 'Moo/Object.pm', 'Moo/_Utils.pm', 'Moo/sification.pm', 'Scalar/Util.pm', 'Sub/Util.pm', 'XSLoader.pm', 'bytes.pm', 'constant.pm', 'mro.pm', 'overloading.pm', 'strict.pm', 'warnings.pm', 'warnings/register.pm' ];

    So you can see that the utf8 pragma isn't enabled by default by Moo.

    Can you provide a self-contained code snippet that demonstrates the namespace::clean issue? Also within the namespace::clean documentation, it does mention that you can pass an -except => [qw(foo bar)]; list of subs not to clean. Doing so may improve your experience.


    Dave

      Thank you very much for "warn Dumper sort keys %INC" - this is brilliant.

      The problem with namespace:

      use utf8; use feature qw(signatures); no warnings qw(experimental::signatures); use Moo; use namespace::clean; sub BUILD($self) { $self->_set_count(1); }

      An error: "The signatures feature is experimental ..."

      Should I place no warnings after namespace::clean or there are other solutions? Maybe with namespace::clean -except?

        The "problem" with Moo is that it re-enables all warnings that you previously disabled.

        So a solution is to disable warnings after the use Moo; line:

        use utf8; use feature qw(signatures); use Moo; no warnings qw(experimental::signatures);
Re: use utf8 pragma with moo
by ikegami (Patriarch) on Jan 14, 2022 at 19:07 UTC

    If you're source code is encoded using UTF-8, add use utf8;.

    If you're source code is encoded using ASCII, don't use use utf8;.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (2)
As of 2024-04-26 03:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found