perl5

How do I collect coverage from child processes when running `cover -test`, and not otherwise? (Devel::Cover)

只愿长相守 提交于 2020-01-14 10:42:37
问题 (I think I've seen the answer to this, but I can't find it again. The closest I have come across is this question). I am hacking on prt and am trying to get full coverage data for my changes. Some of my new tests call system($^X, 'prt', ...) to run child processes. I then test the output of those processes. However, Devel::Cover does not collect coverage data in the child processes. How do I collect that data, without causing Devel::Cover to run when I do a regular make test ? Currently I

Class::DBI - does it load all tables?

一世执手 提交于 2019-12-24 14:34:32
问题 We have a MySQL database with very big number of tables. Unfortunately in 2018 we still use Perl CGI. So loading time of a script is essential. DBIx::Class was ruled out by me because it loads about 1.6 sec (so long because it loads Perl definitions for all tables of the DB) what is clearly too much. How quickly Class::DBI loads? My main question: Does Perl load information about all available tables (like DBIx::Class does) when we use Class::DBI or does it load Perl definitions for only

Can't use string (“1”) as a subroutine ref while “strict refs” in use

巧了我就是萌 提交于 2019-12-22 09:12:11
问题 In a Perl daemon reacting to various events I'm trying to use a Null object pattern in 2 cases by creating anonymous subroutines, which should just return a value of 1 aka "true" (please scroll to the right to see the check subroutines for LOGIN and ALIVE events): package User; our %EVENTS = ( LOGIN => {handler => \&handleLogin, check => sub {1}, }, CHAT => {handler => \&handleChat, check => \&mayChat, }, JOIN => {handler => \&handleJoin, check => \&mayJoin, }, LEAVE => {handler => \

What is indirect object notation, why is it bad, and how does one avoid it?

孤者浪人 提交于 2019-12-17 16:56:11
问题 The title pretty much sums it up, but here's the long version anyway. After posting a small snippet of perl code, I was told to avoid indirect object notation, "as it has several side effects". The comment referenced this particular line: my $some_object = new Some::Module(FIELD => 'value'); As this is how I've always done it, in an effort to get with the times I therefore ask: What's so bad about it? (specifically) What are the potential (presumably negative) side effects? How should that

Perl 5.20 and the fate of smart matching and given-when?

我们两清 提交于 2019-12-17 05:05:08
问题 I just installed Perl 5.18, and I get a lot of warnings like this, given is experimental at .\[...].pl line [...]. when is experimental at .\[...].pl line [...]. Smartmatch is experimental at C:/strawberry/perl/site/lib/[...] line [...]. Looking into these warnings -- which I've never heard mentioned anywhere -- I was only able to find this in two places, perldelta for 5.18, which only really mentions insofar as to say that the feature has been downgraded to experimental ? this nntp.perl.org

DBIx::Class resultset creating related data without the select

南笙酒味 提交于 2019-12-13 00:41:16
问题 I'm trying to do something akin to this: $schema->resultset('Foo')->create({ Property => 1, Bar => { Property => 'non-unique', }, }); Where Bar is a belongs_to relation to another table, Bar, with an auto-incrementing primary key. Problem is that behind the scenes, dbix is always doing a select and finding an existing row in Bar with Property = 'non-unique', and inserting that row's PK into Foo. What I'd like it to do instead is create a new row in Bar each time with a new auto-generated

Perl hashes don't work as expected

丶灬走出姿态 提交于 2019-12-12 19:23:18
问题 #!/usr/bin/perl sub f { { a => 1, b => 2 } } sub g { { %{f()}, c => 3, d => 4, } } use Data::Dumper; print Dumper g(); The above code outputs $VAR1 = 'a'; $VAR2 = 1; $VAR3 = 'b'; $VAR4 = 2; $VAR5 = 'c'; $VAR6 = 3; $VAR7 = 'd'; $VAR8 = 4; despite in my understanding it should output $VAR1 = { 'a' => 1, 'c' => 3, 'b' => 2, 'd' => 4 }; What is my misunderstanding? 回答1: The problem is that a pair of braces is ambiguous in Perl, and may be either a block or an anonymous hash Because of the

Reliable Perl encoding with File::Slurp

你说的曾经没有我的故事 提交于 2019-12-12 01:54:34
问题 I need to replace every occurrence of http:// with // in a file. The file may be (at least) in UTF-8 , CP1251 , or CP1255 . Does the following work? use File::Slurp; my $Text = read_file($File, binmode=>':raw'); $Text =~ s{http://}{//}gi; write_file($File, {atomic=>1, binmode=>':raw'}, $Text); It seems correct, but I need to be sure that the file will not be damaged whatever encoding it has. Please help me to be sure. 回答1: This answer won't make you sure, though I hope it can help. I don't

How does Perl handle the shebang line?

夙愿已清 提交于 2019-12-11 03:23:45
问题 I'm trying to understand how perl deals with the shebang line. I used to think that any interpreter mentioned in the "command position" on the command line would take precedence over one mentioned in the shebang line. For example, if an executable script called demo looks like this #!/usr/local/bin/perl-5.00503 printf "$]\n"; ...then I would observe the following: $ ./demo 5.00503 % /usr/local/bin/perl-5.22 ./demo 5.022003 IOW, in the first execution, the interpreter in the shebang is the one

In Perl 5, how to queue a process/application after it reaches a maximum limit

夙愿已清 提交于 2019-12-10 11:45:46
问题 I have a program that is being symlinked to multiple directories e.g. /main/foo.pl /run1/foo.pl -> /main/foo.pl /run2/foo.pl -> /main/foo.pl /run3/foo.pl -> /main/foo.pl /run4/foo.pl -> /main/foo.pl They're being run as cron jobs, hence I have the following entries in the crontab: */2 * * * * /run1/foo.pl */2 * * * * /run2/foo.pl */2 * * * * /run3/foo.pl */2 * * * * /run4/foo.pl A snippet of foo.pl is as below: use Fcntl qw(:flock); use autodie qw(:all); open my $self, '>', "$FindBin::Bin