[Catalyst] Problem flattening arrays in Catalyst/Helper/Model/DBIC/Schema

pablo marin-garcia harpactocrates at googlemail.com
Fri Aug 28 17:11:54 GMT 2009


Hello Tom,

thanks for your answer

On Thu, Aug 27, 2009 at 11:45 PM, Tomas Doran<bobtfish at bobtfish.net> wrote:
>
> On 27 Aug 2009, at 21:52, pablo marin-garcia wrote:

> Nono, that isn't a Moose feature at all..
>
> It's the use of Moose::Autobox which allows you to lexically call stuff...
> So for example:
>
> use Moose::Autobox;
> my @list = 2->flatten;
> my @other_list = [ 2 ]->flatten;
> is_deeply \@list, \@other_list;
>
>>> I'm just not seeing how Moose::Autobox can pass it's tests for you (which
>>> involve ->flatten working), but fail when run for real..

The reason the the autobox pass is because they are not testing
'flatten' or 'to' or other 'methods' like that.

Looking deeply on autobox, I have seen that what it does it to call
SCALAR::the_function, ARRAY::the_function...etc depending of the ref()
or your 'object'

Then I unpacked the autobox tar and changed the tests and added a call
for flatten. It fails. But if I define the sub ARRAY::flatten {} it
works:

-----
$ cat t/flatten.t
use autobox;
use Test::More;
use Data::Dumper;

sub SCALAR::to_upper { uc $_[0] }
sub SCALAR::flatten {[$_[0]]}
sub SCALAR::to { $_[0]. '_to_'.$_[1]}
sub ARRAY::flatten{$_[0]}

my $range = eval{10->to(1)};
print Dumper $range;
is_deeply ($range, '10_to_1' , "autobox ->to test") or diag ($@);

my @list = eval{ 2->flatten} || 2;
my @other_list = eval{[ 2 ]->flatten}||[2];
is_deeply (\@list, \@other_list, "testing autobox flatten") or diag ("$@");


is('hello'->to_upper, 'HELLO', 'autobox is enabled');

-----

This test works with the subs defined:
>   make test
>  [...]
>  t/flatten.t .... 1/? # Tests were run but no plan was declared and done_testing() was not seen.
>  t/flatten.t .... All 3 subtests passed
>  [...]

But it fails *without* the subs ARRAY, SCALAR etc:

#   Failed test 'autobox ->to test'
#   at t/flatten.t line 16.
#          got: undef
#     expected: '10_to_1'
# Can't call method "to" without a package or object reference at
t/flatten.t line 14.

#   Failed test 'testing autobox flatten'
#   at t/flatten.t line 20.
#     Structures begin differing at:
#          $got->[0] = '2'
#     $expected->[0] = ARRAY(0x81f88c0)
# Can't call method "flatten" on unblessed reference at t/flatten.t line 19.
Can't locate object method "to_upper" via package "hello" (perhaps you
forgot to load "hello"?) at t/flatten.t line 23.

This drive me to the conclusion that somewere the  xxx::flaten mehtod
is not defined, so I am missing the module where this is defined,
probably in Moose::Autobox:: or autobox:: submodules

So someone knows where the Moose::Autobox::ARRAY::flatten lives (or
whatever is the namespace given to it)?

Am I in the right path of reasoning or I have missed something? I am
new to all this 'perl6' magic like autobox implementation and 'modern
perl'.

BUT the thing that drive me crazy is that the 'make test' done
manually was ok with the SCALAR etc subs, but when I run calling only
the test it FAILED!!!!!

=======
pg4 at deskpro17122[~/.cpan/build/autobox-2.55-RKhwNV]226
$ perl t/flatten.t
$VAR1 = undef;
not ok 1 - autobox ->to test
#   Failed test 'autobox ->to test'
#   at t/flatten.t line 16.
#          got: undef
#     expected: '10_to_1'
# Can't call method "to" without a package or object reference at
t/flatten.t line 14.
not ok 2 - testing autobox flatten
#   Failed test 'testing autobox flatten'
#   at t/flatten.t line 20.
#     Structures begin differing at:
#          $got->[0] = '2'
#     $expected->[0] = ARRAY(0x81f8904)
# Can't call method "flatten" on unblessed reference at t/flatten.t line 19.
Can't locate object method "to_upper" via package "hello" (perhaps you
forgot to load "hello"?) at t/flatten.t line 23.
# Tests were run but no plan was declared and done_testing() was nots seen.

[~/.cpan/build/autobox-2.55-RKhwNV]227
$ make test
PERL_DL_NONLAZY=1 /software/perl-5.8.8/bin/perl
"-MExtUtils::Command::MM" "-e" "test_harness(0, 'blib/lib',
'blib/arch')" t/*.t
t/all.t ........ ok
t/autoref.t .... ok
t/coderef.t .... ok
t/default.t .... ok
t/export.t ..... ok
t/flatten.t .... 1/? # Tests were run but no plan was declared and
done_testing() was not seen.
t/flatten.t .... All 3 subtests passed
[..]
=======

I will think about it during the long weekend ;-)

Definitively I have some misconfigurations somewhere :-(

Regards

  Pablo

PS:

About mi perl installation:

>> cpan[1]> m /Autobox/
>
> Those are versions in your CPAN index, not the versions you have installed.

Yes, I know this, but as you can see there was an '=' sign

Module  = Moose::Autobox::Indexed (RJBS/Moose-Autobox-0.09.tar.gz)

telling that I am up to date, so it was not necesary to go go to the :

$ perl -mautobox -e 'print $autobox::VERSION'
2.55
$ perl -mMoose::Autobox -e 'print $Moose::Autobox::VERSION'
0.09

I have installed autobox in
$ find . -name '*autobox*'
./man/man3/autobox.3pm
./perllib/i486-linux-gnu-thread-multi/auto/autobox
./perllib/i486-linux-gnu-thread-multi/auto/autobox/autobox.so
./perllib/i486-linux-gnu-thread-multi/auto/autobox/autobox.bs
./perllib/i486-linux-gnu-thread-multi/autobox
./perllib/i486-linux-gnu-thread-multi/autobox.pod
./perllib/i486-linux-gnu-thread-multi/autobox.pm

 and my my perl -V
$ perl -V
Summary of my perl5 (revision 5 version 8 subversion 8) configuration:
  Platform:
    osname=linux, osvers=2.6.8lustre, archname=i686-linux-thread-multi
    uname='linux bc-1-2-01 2.6.8lustre #1 smp mon oct 17 13:36:09 bst
2005 i686 gnulinux '
    config_args=''
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=define use5005threads=undef useithreads=define
usemultiplicity=define
    useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
    use64bitint=undef use64bitall=undef uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='gcc-3.4', ccflags ='-D_REENTRANT -D_GNU_SOURCE
-DTHREADS_HAVE_PIDS -fno-strict-aliasing -pipe
-Wdeclaration-after-statement -I/usr/local/include -D_LARGEFILE_SOURCE
-D_FILE_OFFSET_BITS=64',
    optimize='-O2',
    cppflags='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS
-fno-strict-aliasing -pipe -Wdeclaration-after-statement
-I/usr/local/include'
    ccversion='', gccversion='3.4.4 20050314 (prerelease) (Debian
3.4.3-13sarge1)', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t',
lseeksize=8
    alignbytes=4, prototype=define
  Linker and Libraries:
    ld='gcc-3.4', ldflags =' -L/usr/local/lib'
    libpth=/usr/local/lib /lib /usr/lib
    libs=-lnsl -lgdbm -ldb -ldl -lm -lcrypt -lutil -lpthread -lc
    perllibs=-lnsl -ldl -lm -lcrypt -lutil -lpthread -lc
    libc=/lib/libc-2.3.2.so, so=so, useshrplib=true, libperl=libperl.so
    gnulibc_version='2.3.2'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E
-Wl,-rpath,/software/perl-5.8.8/lib/5.8.8/i686-linux-thread-multi/CORE'
    cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib'


Characteristics of this binary (from libperl):
  Compile-time options: MULTIPLICITY PERL_IMPLICIT_CONTEXT
                        PERL_MALLOC_WRAP THREADS_HAVE_PIDS USE_ITHREADS
                        USE_LARGE_FILES USE_PERLIO USE_REENTRANT_API
  Built under linux
  Compiled at Jan  8 2007 15:50:11
  %ENV:

  @INC:
    /nfs/users/nfs_p/pg4/local_perl/perllib/i686-linux-thread-multi
    /nfs/users/nfs_p/pg4/local_perl/perllib
    /nfs/users/nfs_p/pg4/local_perl/lib/perl5/
    /nfs/users/nfs_p/pg4/local_perl/perllib/i486-linux-gnu-thread-multi
    /nfs/users/nfs_p/pg4/local_perl/perllib/i386-linux-thread-multi
    /software/perl-5.8.8/lib/5.8.8/i686-linux-thread-multi
    /software/perl-5.8.8/lib/5.8.8
    /software/perl-5.8.8/lib/site_perl/5.8.8/i686-linux-thread-multi
    /software/perl-5.8.8/lib/site_perl/5.8.8
    /software/perl-5.8.8/lib/site_perl
    .



-- 
   - Pablo Marin-Garcia



More information about the Catalyst mailing list