Subject: | Cyclical include of MCE::Map leads to failures |
Date: | Mon, 28 Sep 2015 15:22:48 +0200 |
To: | bug-MCE [...] rt.cpan.org |
From: | Kai Wasserbäch <kaw [...] heise.de> |
Hi,
I have a funny problem when using mce_map, which I believe is a bug.
I have code, that fetches a set of rows from a database, using
DBIx::Class. Afterwards I want to initialise an Object for each row.
The code looks like this (in, say, module MyObject::List):
my @aRows = $oDbh->resultset('TblName')->search({
field1 => 1
field2 => 'foo'
}, {
order_by => {-asc => 'date.start'},
join => 'date'
});
my @aObjs = map {
MyObject->new({
id => $_->tbl_name_id,
data => $_
})
} @aRows;
return \@aObjs
MyObject uses another object (MyOtherObject::List), which in turn also
relies on MCE::Map for faster object list generation.
Now, as long as I have the map {} there, everything works, but as soon
as I replace it with mce_map I get an error, telling me "tbl_name_id"
can't be called on an undefined value (»Can't call method "tbl_name_id"
on an undefined value at [...]«).
Since DBIx::Class needs its Schema reference and thawing can lose that,
I override thaw in MCE. I've defined a common method for this:
sub _thaw {
state $oDbh = My::DBIX::Schema->new;
# ie. calling
<http://search.cpan.org/~ribasushi/DBIx-Class-0.082820/lib/DBIx/Class/Schema.pm#thaw>
return $oDbh->thaw(@_);
}
which is passed to MCE like
use MCE::Map
thaw => \&_thaw
;
$oDbh is my DBIx::Class schema.
The problem seems to be, that MCE::Map is included multiple times
(MyObject::List (has "use MCE::Map") builds list of MyObjects. MyObject
uses another object list (MyOtherObject::List), which in turn uses
MCE::Map) and something gets overwritten in between those includes. If I
remove the "use MyOtherObject::List" from MyObject, everything works again.
I'm using Perl (and the modules) as present in Debian testing:
- Perl 5.20.2
- DBIx::Class 0.082820-1
- Moo 2.000001-3
- MCE 1.608-1
Let me know, if you need something else.
Cheers,
Kai
--
Kai Wasserbäch, Softwareentwicklung
c’t – Magazin für Computertechnik
Heise Medien GmbH & Co. KG
Karl-Wiechert-Allee 10
30625 Hannover
Tel.: +49 [0] 511 5352-338
Fax: +49 [0] 511 5352-417
E-Mail: kaw@heise.de
GnuPG: 0x07C9D0B9 / 126D 0DC8 7EF2 E088 3A86 2A6C 4142 C9A8 07C9 D0B9
URL: <http://ct.de/>
Registergericht: Amtsgericht Hannover HRA 26709
Persönlich haftende Gesellschafterin:
Heise Medien Geschäftsführung GmbH
Registergericht: Amtsgericht Hannover, HRB 60405
Geschäftsführer: Ansgar Heise, Dr. Alfons Schräder
Encrypted communication (PGP/MIME) preferred.