Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

DBIx::Class::Schema::Loader: can't load schema

by jds17 (Pilgrim)
on Dec 03, 2012 at 20:52 UTC ( #1006950=perlquestion: print w/replies, xml ) Need Help??
jds17 has asked for the wisdom of the Perl Monks concerning the following question:

Update / Bug found!

I found the reason why the module could not be loaded. Before the call to the method make_schema_at of DBIx::Class::Schema::Loader, @INC contained the current directory '.'. After the call, though, this entry has disappeared from @INC. Would you consider this as a bug or am I too reckless assuming @INC would not be touched?

Dear Perl Monks,

as I am trying to get something to work using DBIx::Class::Schema::Loader , I keep bumping my head against some issues. The first is the following:

I have an SQLite database on disk and want to dump its DBIx::Class schema and connect to the schema immediately afterwards. The test code is as follows:

sub dump_and_import_schema { my ($dsn, $user, $password) = @_; my $attrs = { debug => 0, dump_directory => '.', exclude => qr/(?^:\bBIN)/ }; my $connect_info = [ $dsn, $user, $password ]; push @$connect_info, { on_connect_do => 'PRAGMA foreign_keys = ON' + }; make_schema_at( 'TDG::Schema', $attrs, $connect_info ); eval { require TDG::Schema; TDG::Schema->import(); 1; } or do { my $error = $@; croak $error; }; $dbic_schema = TDG::Schema->connect( $dsn, $user, $password, '' ); }

If I run this (passing appropriate connection parameters), I get the following error:

'Can\'t locate TDG/ in @INC (@INC contains: C:/strawberry/per +l/site/lib C:/strawberry/perl/vendor/lib C:/strawberry/perl/lib) at f line 57.

Now, if I put the call to make_schema_at in a separate script and call it as follows:

sub dump_and_import_schema { my ($dsn, $user, $password) = @_; my $cmd = 'perl ' . File::Spec->catdir( $own_path, '' ) . ' --dsn ' . $dsn; $cmd .= ' --user ' . $user if $user; $cmd .= ' --password ' . $password if $password; $cmd .= ' --dumpdir .'; $cmd .= ' --exclude \bBIN'; system($cmd) == 0 or croak "system $cmd failed: $?"; eval { require TDG::Schema; ...
everything works fine. Or, if I run the original script two times, the first time after having added an exit() after the call to make_schema_at and the second time after having commented out the call to make_schema_at, everything runs fine, too.

I ran the program in a debugger and put a breakpoint immediately after the call to make_schema_at, made a backup of the resulting schema dump and compared it to the result one gets when exiting after having dumped it. There is no difference, i.e. it was not the case that something has not been written to disk yet.

Please enlighten my troubled brain: Why does dump_and_import_schema not work as expected?

Update: Improved readability of title and first sentence.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1006950]
Approved by kcott
[erix]: ah! Those germans again! ... they have a lot to answer for ;-)

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (9)
As of 2018-06-19 09:12 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (111 votes). Check out past polls.