[Dbix-class] Should this work?
Matt Whipple
matt at mattwhipple.com
Tue Sep 15 20:03:58 GMT 2009
> =============== 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@lists.scsys.co.uk
>
More information about the DBIx-Class
mailing list