using
$db->dbh as a setter isn't documented, but this approach sounds reasonable if i can get it to work.
this is my test script so far, which is not working:
use DBI;
use Rose::DB;
my $dbh = DBI->connect( 'DBI:mysql:database=mydb', 'user', 'pass' );
my $rdb = Rose::DB->new( driver => "mysql" );
$rdb->dbh( $dbh );
print "still here\n";
produces:
No database information found for domain 'default' and type 'default' at rdttest.pl line 6
what do i do here instead if i don't want to do the
register_db stuff(or can't, because in the non-simplified case i don't have the DSN, only a
$dbh that was exported from elsewhere) ?
update:
it looks like this works, clunky as it seems:
use base qw( Rose::DB );
__PACKAGE__->use_private_registry;
__PACKAGE__->register_db(
driver => 'mysql',
database => 'fake',
host => 'fake',
username => 'fake',
password => 'fake'
);
package My::RDBO::User;
use base qw( Rose::DB::Object );
use DBI;
__PACKAGE__->meta->setup(
table => 'user',
columns => [qw( id username password email name )],
pk_columns => 'id',
unique_key => 'username',
);
sub init_db {
my $dbh = DBI->connect( 'DBI:mysql:database=mydb', 'user', 'pass'
+);
my $rdb = My::RDB->new;
$rdb->dbh($dbh);
return $rdb;
}
package main;
my $u = My::RDBO::User->new(id => 1);
$u->load;
print("$_ => ", $u->$_, "\n") foreach $u->meta->columns;
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.