Skip Menu |
 

This queue is for tickets about the Moo CPAN distribution.

Report information
The Basics
Id: 127000
Status: new
Priority: 0/
Queue: Moo

People
Owner: Nobody in particular
Requestors: valderrama [...] strato.de
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: Attribute initialization vs Module loading
Date: Thu, 30 Aug 2018 15:12:53 +0000
To: "bug-Moo [...] rt.cpan.org" <bug-Moo [...] rt.cpan.org>
From: "Valderrama, Mario" <valderrama [...] strato.de>
Download (untitled) / with headers
text/plain 1.1k
Hello, I know this is probably not the best way to do this, but creating objects of subclasses from a function in the superclass doesn't correctly initalize the attributes. Say I have 3 files: Foo.pm package Foo; use Moo; use FooBar; has foo => (is => 'ro'); sub make_foobar { FooBar->new(@_) } 1; FooBar.pm package FooBar; use Moo; extends 'Foo'; has bar => (is => 'ro'); 1; main.pl #!/usr/bin/env perl use strict; use warnings; use 5.026; use lib '.'; use Foo; my $foobar = Foo::make_foobar(foo => 'foo', bar => 'bar'); say $foobar->foo(); say $foobar->bar(); Invoking main.pl will yield the following: $ perl main.pl Use of uninitialized value in say at main.pl line 9. bar This however can be fixed by either adding a 'use FooBar;' before the 'use Foo;' in main.pl or by using Moose instead of Moo in any of the two modules. Making one of these changes will then result in: $ perl main.pl foo bar I'm using: - Perl 5.26.0 (installed with plenv) - Moo 2.003004 - Moose 2.2011 (for reference) - Fedora 28 with Kernel 4.17.18-200.x86_64
Download Foo.pm
text/x-perl 101b

Message body is not shown because sender requested not to inline it.

Download FooBar.pm
text/x-perl 71b

Message body is not shown because sender requested not to inline it.

Download main.pl
text/x-perl 181b

Message body is not shown because sender requested not to inline it.



This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.