Skip Menu |

This queue is for tickets about the Moo CPAN distribution.

Report information
The Basics
Id: 82770
Status: resolved
Priority: 0/
Queue: Moo

People
Owner: Nobody in particular
Requestors: stas [...] sysd.org
Cc: djerius [...] cpan.org
AdminCc:

Bug Information
Severity: Normal
Broken in: 1.000007
Fixed in: 1.002000



Subject: BUILDARGS is broken when extends() is used.
Summary of my perl5 (revision 5 version 16 subversion 2) configuration: Platform: osname=linux, osvers=3.0.0-26-generic, archname=x86_64-linux uname='linux bp0907 3.0.0-26-generic #43-ubuntu smp tue sep 25 17:19:22 utc 2012 x86_64 x86_64 x86_64 gnulinux ' config_args='-de -Dprefix=/home/stas/perl5/perlbrew/perls/perl- 5.16.0 -Aeval:scriptdir=/home/stas/perl5/perlbrew/perls/perl-5.16.0/bin' hint=recommended, useposix=true, d_sigaction=define useithreads=undef, usemultiplicity=undef useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef use64bitint=define, use64bitall=define, uselongdouble=undef usemymalloc=n, bincompat5005=undef Compiler: cc='cc', ccflags ='-fno-strict-aliasing -pipe -fstack-protector - I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64', optimize='-O2', cppflags='-fno-strict-aliasing -pipe -fstack-protector - I/usr/local/include' ccversion='', gccversion='4.6.1', gccosandvers='' intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678 d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16 ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8 alignbytes=8, prototype=define Linker and Libraries: ld='cc', ldflags =' -fstack-protector -L/usr/local/lib' libpth=/usr/local/lib /lib/x86_64-linux-gnu /lib/../lib /usr/lib/x86_64-linux-gnu /usr/lib/../lib /lib /usr/lib libs=-lnsl -ldb -ldl -lm -lcrypt -lutil -lc perllibs=-lnsl -ldl -lm -lcrypt -lutil -lc libc=, so=so, useshrplib=false, libperl=libperl.a gnulibc_version='2.13' Dynamic Linking: dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E' cccdlflags='-fPIC', lddlflags='-shared -O2 -L/usr/local/lib -fstack- protector' Characteristics of this binary (from libperl): Compile-time options: HAS_TIMES PERLIO_LAYERS PERL_DONT_CREATE_GVSV PERL_MALLOC_WRAP PERL_PRESERVE_IVUV USE_64_BIT_ALL USE_64_BIT_INT USE_LARGE_FILES USE_LOCALE USE_LOCALE_COLLATE USE_LOCALE_CTYPE USE_LOCALE_NUMERIC USE_PERLIO USE_PERL_ATOF Built under linux Compiled at Nov 5 2012 10:01:56 %ENV: PERLBREW_BASHRC_VERSION="0.56" PERLBREW_HOME="/home/stas/.perlbrew" PERLBREW_MANPATH="/home/stas/perl5/perlbrew/perls/perl-5.16.0/man" PERLBREW_PATH="/home/stas/perl5/perlbrew/bin:/home/stas/perl5/perlbrew/p erls/perl-5.16.0/bin" PERLBREW_PERL="perl-5.16.0" PERLBREW_ROOT="/home/stas/perl5/perlbrew" PERLBREW_VERSION="0.56" PERL_MM_USE_DEFAULT="1" @INC: /home/stas/perl5/perlbrew/perls/perl- 5.16.0/lib/site_perl/5.16.2/x86_64-linux /home/stas/perl5/perlbrew/perls/perl-5.16.0/lib/site_perl/5.16.2 /home/stas/perl5/perlbrew/perls/perl-5.16.0/lib/5.16.2/x86_64-linux /home/stas/perl5/perlbrew/perls/perl-5.16.0/lib/5.16.2 /home/stas/perl5/perlbrew/perls/perl- 5.16.0/lib/site_perl/5.16.1/x86_64-linux /home/stas/perl5/perlbrew/perls/perl-5.16.0/lib/site_perl/5.16.1 /home/stas/perl5/perlbrew/perls/perl- 5.16.0/lib/site_perl/5.16.0/x86_64-linux /home/stas/perl5/perlbrew/perls/perl-5.16.0/lib/site_perl/5.16.0 /home/stas/perl5/perlbrew/perls/perl-5.16.0/lib/site_perl .
Subject: Wrapper.pm
package Wrapper; use strict; use warnings; use Moo; use Scalar::Util qw(set_prototype); set_prototype \&new => undef; # no extends: 3x base64 extends 'Benchmark'; # 3x Not a HASH reference at (eval 15) line 21. #extends 'Digest::MD5'; # 3x Usage: Digest::MD5::new(xclass) at (eval 13) line 19. #extends 'Digest::SHA'; # 3x Can't call method "type" on unblessed reference at __FILE__ line __LINE__. #extends 'LWP::UserAgent'; # "base64", "Options to LWP::UserAgent should be key/value pairs, not hash reference at (eval 15) line 19.", "base64" #extends 'Net::Curl::Easy'; # "object base must be a valid reference", "base64", "Usage: Net::Curl::Easy::new(sclass="Net::Curl::Easy", base=HASHREF_BY_DEFAULT) at (eval 13) line 19." has type => (is => 'ro', required => 1); sub BUILDARGS { my ($class, @args) = @_; if (@args == 1 and q(HASH) eq ref $args[0]) { return $args[0]; } elsif (@args == 1) { return { type => $args[0] }; } elsif (@args % 2 == 0) { return { @args }; } else { die "error"; } } =for comment # using "around new" instead seems to solve for Net::Curl::Easy, while breaking LWP::UserAgent even badder! around new => sub { my $orig = shift; my $self = shift; if (@_ == 1 and q(HASH) eq ref $_[0]) { return $orig->($self => shift); } elsif (@_ == 1) { return $orig->($self => { type => shift }); } elsif (@_ % 2 == 0) { return $orig->($self => { @_ }); } else { die "error"; } }; =cut 1; package main; use strict; use warnings; for my $arg ( ["base64"], [{ type => "base64" }], [type => "base64"], ) { eval { my $md5 = Wrapper->new(@$arg); print $md5->type, "\n"; }; warn $@ if $@; }
There are two basic issues here. First is that some non-Moo classes don't use hashref for their objects, preventing Moo from having anywhere to store its attributes. To deal with that, I've released MooX::InsideOut, which should allow you to subclass any type of object. Second is that some constructors are more restrictive in how they handle their parameters. It's possible to use BUILDARGS to get the arguments conforming to what Moo expects, but the original arguments will still be passed through to the super-class constructor. The plan is to implement a sub FOREIGNBUILDARGS (mirroring what MooseX::NonMoose uses) so you can modify the arguments as needed for the super-class. I've started the foreignbuildargs branch in the Moo repo with a work in progress on this.
Tested the foreignbuildargs branch with the Moo port of my previously- Any::Moose-based module. The BUILDARGS/FOREIGNBUILDARGS is now 100% compatible, thank you! Em Sex Fev 22 05:08:21 2013, haarg escreveu: Show quoted text
> There are two basic issues here. First is that some non-Moo classes > don't use hashref for their objects, preventing Moo from having
anywhere Show quoted text
> to store its attributes. To deal with that, I've released > MooX::InsideOut, which should allow you to subclass any type of
object. Show quoted text
> > Second is that some constructors are more restrictive in how they
handle Show quoted text
> their parameters. It's possible to use BUILDARGS to get the arguments > conforming to what Moo expects, but the original arguments will still
be Show quoted text
> passed through to the super-class constructor. The plan is to
implement Show quoted text
> a sub FOREIGNBUILDARGS (mirroring what MooseX::NonMoose uses) so you
can Show quoted text
> modify the arguments as needed for the super-class. > > I've started the foreignbuildargs branch in the Moo repo with a work
in Show quoted text
> progress on this.
Support for FOREIGNBUILDARGS has been merged and released in Moo 1.00100, but there is not yet any documentation for it. I'm leaving this open until that is done.
Moo 1.002000 now documents FOREIGNBUILDARGS, so this is now resolved.