Should this work?

9 messages Options
Embed this post
Permalink
Dermot

Should this work?

Reply Threaded More More options
Print post
Permalink
Hi,

I'm getting this error:
DBIx::Class::ResultSet::create(): create needs a hashref at insert.t line 22

from the script below.  I believe I am passing a hashref. I suspect
there is a problem with my Perl (5.10.0) but I might also be making a
newbie error.

Thanx,
Dp.


=============== script ===========
#!/bin/perl

use strict;
use warnings;
#use Crap;          # Why isn't there a crap in my distro?
use FindBin qw/$Bin/;
use Data::Dumper;

use lib "$Bin/../lib";
use SPL::Schema;

my $hashref = {
    number   => 'A100/0002',
    title          => 'A Title',
    codixId     => 651000002,
    };

my $schema = SPL::Schema->resultset('Assets');
             die "Can't connect $@\n" unless $schema;
print Dumper($ref);
$schema->create->($ref) or warn "Error inserting: $@\n";

======== output ========
$VAR1 = {
          'codixId' => 651000002,
          'title' => 'A Title',
          'splNumber' => 'A100/0002'
        };
create needs a hashref at
/usr/local/share/perl/5.10.0/DBIx/Class/Schema.pm line 1027
        DBIx::Class::Schema::throw_exception('SPL::Schema', 'create needs a
hashref') called at
/usr/local/share/perl/5.10.0/DBIx/Class/ResultSet.pm line 3090
        DBIx::Class::ResultSet::throw_exception('DBIx::Class::ResultSet=HASH(0x861a4e8)',
'create needs a hashref') called at
/usr/local/share/perl/5.10.0/DBIx/Class/ResultSet.pm line 2298
        DBIx::Class::ResultSet::create('DBIx::Class::ResultSet=HASH(0x861a4e8)')
called at insert.t line 22

_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/dbix-class@...
Rob Kinyon

Re: Should this work?

Reply Threaded More More options
Print post
Permalink
On Tue, Sep 15, 2009 at 15:49, Dermot <[hidden email]> wrote:
[snip]
> $schema->create->($ref) or warn "Error inserting: $@\n";
[snip]

$schema->create( $ref );

$schema->create->($ref) calls create() with no arguments.

_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/dbix-class@...
Samuel Baldwin-2

Re: Should this work?

Reply Threaded More More options
Print post
Permalink
In reply to this post by Dermot
2009/9/15 Dermot <[hidden email]>:
> #use Crap;          # Why isn't there a crap in my distro?

Pretty sure it's "use Carp;".
--
Samuel Baldwin - logik.li
My other computer is an abacus.

_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/dbix-class@...
Ash Berlin

Re: Should this work?

Reply Threaded More More options
Print post
Permalink
In reply to this post by Dermot

On 15 Sep 2009, at 20:49, Dermot wrote:

>
> $schema->create->($ref) or warn "Error inserting: $@\n";

You want $schema->create($ref). Not the extra '->' in your version.

_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/dbix-class@...
Matt Whipple

Re: Should this work?

Reply Threaded More More options
Print post
Permalink
In reply to this post by Dermot

> =============== script ===========
> #!/bin/perl
>
> use strict;
> use warnings;
> #use Crap;          # Why isn't there a crap in my distro?
>  
You may be looking for "Carp".  I personally would try to keep Crap out
of my code.

> use FindBin qw/$Bin/;
> use Data::Dumper;
>
> use lib "$Bin/../lib";
> use SPL::Schema;
>
> my $hashref = {
>     number   => 'A100/0002',
>     title          => 'A Title',
>     codixId     => 651000002,
>     };
>
> my $schema = SPL::Schema->resultset('Assets');
>              die "Can't connect $@\n" unless $schema;
> print Dumper($ref);
> $schema->create->($ref) or warn "Error inserting: $@\n";
>  
You want to pass the ref as an argument to create

$schema->create($ref)

The original code (with the second ->) would be trying to dereference
create and access something within it.

> ======== output ========
> $VAR1 = {
>           'codixId' => 651000002,
>           'title' => 'A Title',
>           'splNumber' => 'A100/0002'
>         };
> create needs a hashref at
> /usr/local/share/perl/5.10.0/DBIx/Class/Schema.pm line 1027
> DBIx::Class::Schema::throw_exception('SPL::Schema', 'create needs a
> hashref') called at
> /usr/local/share/perl/5.10.0/DBIx/Class/ResultSet.pm line 3090
> DBIx::Class::ResultSet::throw_exception('DBIx::Class::ResultSet=HASH(0x861a4e8)',
> 'create needs a hashref') called at
> /usr/local/share/perl/5.10.0/DBIx/Class/ResultSet.pm line 2298
> DBIx::Class::ResultSet::create('DBIx::Class::ResultSet=HASH(0x861a4e8)')
> called at insert.t line 22
>
> _______________________________________________
> List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
> IRC: irc.perl.org#dbix-class
> SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
> Searchable Archive: http://www.grokbase.com/group/dbix-class@...
>  


_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/dbix-class@...
Dermot

Re: Should this work?

Reply Threaded More More options
Print post
Permalink
In reply to this post by Samuel Baldwin-2
2009/9/15 Samuel Baldwin <[hidden email]>:
> 2009/9/15 Dermot <[hidden email]>:
>> #use Crap;          # Why isn't there a crap in my distro?
>
> Pretty sure it's "use Carp;".

Lol, that got to be the mother of all typos.

Thanx create($ref) works en'all.
Dp.

_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/dbix-class@...
Matt Whipple

Re: Should this work?

Reply Threaded More More options
Print post
Permalink
In reply to this post by Matt Whipple

> You want to pass the ref as an argument to create
>
> $schema->create($ref)
>
> The original code (with the second ->) would be trying to dereference
> create and access something within it.
>
Whoops...change that to accessing something within the return value of
create().

>> ======== output ========
>> $VAR1 = {
>>           'codixId' => 651000002,
>>           'title' => 'A Title',
>>           'splNumber' => 'A100/0002'
>>         };
>> create needs a hashref at
>> /usr/local/share/perl/5.10.0/DBIx/Class/Schema.pm line 1027
>>     DBIx::Class::Schema::throw_exception('SPL::Schema', 'create needs a
>> hashref') called at
>> /usr/local/share/perl/5.10.0/DBIx/Class/ResultSet.pm line 3090
>>     DBIx::Class::ResultSet::throw_exception('DBIx::Class::ResultSet=HASH(0x861a4e8)',
>>
>> 'create needs a hashref') called at
>> /usr/local/share/perl/5.10.0/DBIx/Class/ResultSet.pm line 2298
>>     DBIx::Class::ResultSet::create('DBIx::Class::ResultSet=HASH(0x861a4e8)')
>>
>> called at insert.t line 22
>>
>> _______________________________________________
>> List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
>> IRC: irc.perl.org#dbix-class
>> SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
>> Searchable Archive:
>> http://www.grokbase.com/group/dbix-class@...
>>  
>
>
> _______________________________________________
> List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
> IRC: irc.perl.org#dbix-class
> SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
> Searchable Archive:
> http://www.grokbase.com/group/dbix-class@...


_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/dbix-class@...
Dermot

Re: Should this work?

Reply Threaded More More options
Print post
Permalink
2009/9/15 Matt Whipple <[hidden email]>:
>
>> You want to pass the ref as an argument to create
>>
>> $schema->create($ref)

I've made some alterations (including the mega laughable typos) but
I'm still getting un-expected results:

Can't call method "select_single" on an undefined value at
/usr/local/share/perl/5.10.0/DBIx/Class/ResultSet.pm line 740.


==============
#!/bin/perl

use strict;
use warnings;
use Carp;
use FindBin qw/$Bin/;
use Data::Dumper;

use lib "$Bin/../lib";
use SPL::Schema;

my $ref = {
        number        => 'A100/0002',
        title        => 'A Title',
        codixId => 651000002,
        };


my $schema = SPL::Schema->resultset('Assets');
# my $schema = SPL::Schema->resultset('Assets')->search();
die "Can't connect $@\n" unless $schema;
print Dumper($ref);
$schema->find_or_create($ref) or warn "Error inserting: $@\n";
#$schema->create($ref) or warn "Error inserting: $@\n";  prints Can't
call method "insert" on an undefined val
======================

Can anyone spot the error of my ways?
Thanx,
Dp.

_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/dbix-class@...
Ash Berlin

Re: Should this work?

Reply Threaded More More options
Print post
Permalink

On 15 Sep 2009, at 22:25, Dermot wrote:

> 2009/9/15 Matt Whipple <[hidden email]>:
>>
>>> You want to pass the ref as an argument to create
>>>
>>> $schema->create($ref)
>
> I've made some alterations (including the mega laughable typos) but
> I'm still getting un-expected results:
>
> Can't call method "select_single" on an undefined value at
> /usr/local/share/perl/5.10.0/DBIx/Class/ResultSet.pm line 740.
>
>
> ==============
> #!/bin/perl
>
> use strict;
> use warnings;
> use Carp;
> use FindBin qw/$Bin/;
> use Data::Dumper;
>
> use lib "$Bin/../lib";
> use SPL::Schema;
>
> my $ref = {
> number        => 'A100/0002',
> title        => 'A Title',
> codixId => 651000002,
> };
>
>
> my $schema = SPL::Schema->resultset('Assets');
> # my $schema = SPL::Schema->resultset('Assets')->search();
> die "Can't connect $@\n" unless $schema;
> print Dumper($ref);
> $schema->find_or_create($ref) or warn "Error inserting: $@\n";
> #$schema->create($ref) or warn "Error inserting: $@\n";  prints Can't
> call method "insert" on an undefined val
> ======================
>
> Can anyone spot the error of my ways?
> Thanx,
> Dp.

Looks like never connected your schema to a DB. However the error it  
gives leaves a lot to be desired. If you feel up to it, a patch would  
be good, otherwise a bug on rt.cpan.org please.

-ash

_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/dbix-class@...