Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Locked thread
Puck42
Oct 7, 2005

Anyone familiar with DBIx::Class here?

I'm still trying to figure out how it all works, but I'm having an issue using update_or_create.

Every time I run it, I get an invalid syntax error from MySQL.

code:
my $sth = $schema->resultset('Users')->update_or_create({
                                              'username' => $username,
                                              'fullname' => $fullname,
                                              'guid' => $guid
                                                        }, { key =>'users_guid' });
SQL statement being created by DBIx
code:
SELECT me.index, me.username, me.fullname, me.guid FROM users me WHERE \
             ( ( me.guid = ? ) ): '5D65F46C-997A-41F4-BBA4-15494BC57885'
UPDATE users SET fullname = ? WHERE ( index = ? ): 'John Doe', '45'
I do have guid set as a unique constraint in the database and in the module. The statement works perfectly when it inserts a new entry, but fails on an update.

Any ideas?

Puck42 fucked around with this message at 21:45 on Feb 28, 2008

Adbot
ADBOT LOVES YOU

Puck42
Oct 7, 2005

yeah... that was the problem.


I feel like an idiot now. No idea how I forgot all about that.

Puck42
Oct 7, 2005

I've been having this issue for a few weeks now and it's driving me up a wall.


I'm writing a web app using Mason and I have a custom module that contains a lot of common functions.

For some reason now, when ever I add any new function or edit an existing one mod_perl decides that the function doesn't exist and tells me that the subroutine is undefined when I know it is. Once I remove the added lines the function works fine once again.

Anyone ever have a similar issue?

Puck42
Oct 7, 2005

Empty Threats posted:

Tried turning off code caching ?

I have, same thing happens.

Puck42
Oct 7, 2005

Anyone here use HTML::Mason with virtual servers on Apache?

I'm having issues getting it to work with more than 2 sites.

Using PerlOptions +Parent works fine with 2 sites, as does using a handler hash in handler.pl.

But as soon as I add a third site, it starts loading files from the wrong folder. The original 2 still work though, it's just the new one.

Can anyone help?

Puck42
Oct 7, 2005

Thanks to this thread I've started fooling around with Moose. So far I like it. But I'm not too up to date on OO programming.

I've run into one issue I'm not sure how to tackle.

I have an object named Conf that is extended by another object named Admin.
I pull data from a database query and dump that into the Conf object. The admin row of the query returns an index number for another table.

How would I setup the Admin object to take the index number it gets from the query and load it's self from another query? I initially replaced the new function, but I get an Type Constraint error. Which makes sense.

I hope I'm explaining this well enough.

code:
package Conf;
use Moose;

has 'idx' => (is => 'ro', isa => 'Int');
has 'admin' => (is => 'rw', isa => 'Admin');

sub new {
  my ($class, $conf_num) = @_; 
  
  my $sth = $dbh->prepare("SELECT * FROM table WHERE idx = ?;");
  $sth->execute($conf_num);
  my $row = $sth->fetchrow_hashref;
  my $self = $class->SUPER::new(%$row);
  return $self;
}

package Admin;                 
use Moose;
                            
extends 'Conf';

has 'idx' => (is => 'ro', isa => 'Int');
has 'first_name' => (is => 'rw', isa => 'Str');
has 'last_name' => (is => 'rw', isa => 'Str');

package main;

my $conf = Conf->new(21);

Puck42 fucked around with this message at 19:00 on Aug 23, 2009

Puck42
Oct 7, 2005

Filburt Shellbach posted:

I'm not quite sure what you mean here. Since this is the heart of your question, I don't know how to help you with this without more information.


Sorry, it's a horrible way to phrase it.

I have the BUILDARGS run a query and it returns a number for admin, like 4. I then want that number to run through the Admin object as a DB query and setup the Admin object inside of Conf using the hash returned from the Admin query.

Basically the same way I have Conf setup to run the number it receives as a query and create the object.

Speaking of BUILDARGS...

code:
sub BUILDARGS {
  my ($class, $conf_num) = @_; 
  
  my $sth = $dbh->prepare("SELECT * FROM table WHERE idx = ?;");
  $sth->execute($conf_num);
  return $sth->fetchrow_hashref;
}
I can not get BUILDARGS to work, I've tried it a few different ways based off examples, but I always get an error.

code:
Single parameters to new() must be a HASH ref at /usr/share/perl5/Moose/Object.pm line 18
	Moose::Object::new('Conf', 21) called at ./m_test.pl line 64
Any ideas?

Thanks

Edit: Never mind, I should of check the version of Moose installed, 0.17 is not up to date...

Puck42 fucked around with this message at 01:48 on Aug 24, 2009

Adbot
ADBOT LOVES YOU

Puck42
Oct 7, 2005

Another small Moose question.

Is it possible to extend an object and have the extension replace one attribute with another.

For example:
code:
package User;
use Moose;

has 'name'=>(is => 'ro', isa => 'Str');

package UserManip
extends User;
use Moose;

has 'name'=>(is => 'rw', isa => 'Str', trigger => \&change_name);
I'd like to be able to add administration functions to an object without having to create a whole new package.

  • Locked thread