package ODB::Load; use strict; =head1 ODB::Load This isn't meant to be used directly... you need to inherit from it. =cut sub new { my ($class, @ops) = @_; my $self = {@ops}; bless $self, $class; return $self; } =item load() Load / create classes from SQLite DB. =cut sub load { my ($self) = @_; my @tables = $self->tables; # First create all of them foreach my $table_name (@tables) { my $table = ODB::create_class($table_name); } # Then we set up relationships foreach my $table_name (@tables) { my $table = ODB::get_classname($table_name); my @keys = $self->keys($table_name); $table->id_column_names([@keys]); my @cols = $self->cols($table_name); # Look for foreign table references foreach my $col (@cols) { #print "Working on col: '$table_name.$col'\n"; # Look for a foreign key with possible local-name if($col =~ / ^ # Anchor to the front of the string (([^_]+)_)? # Look for an optional alias $2 (no underscores) (([^_]+) # Look for the foreign column name $3 _id)$ # And ending with an _id /x) { my $foreign_table = $4; my $foreign_col = $3; my $name = $2 || $4; # If they gave no alias, default to column name #print "Calling \$add_col->($name, $col, $foreign_table, $foreign_col);\n"; $table->add_col($name, $col, $foreign_table, $foreign_col); } # Then no matter what leave a raw-access method $table->add_col($col, $col); } } } 1;