Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Re^4: A Growing Dislike for SQL-OOP Mappers

by jk2addict (Chaplain)
on Aug 22, 2005 at 21:33 UTC ( #485776=note: print w/replies, xml ) Need Help??

in reply to Re^3: A Growing Dislike for SQL-OOP Mappers
in thread A Growing Dislike for SQL-OOP Mappers

If you create an infinite loop or somesuch thing by overriding create, you should reconsider your strategy

I agree. So, who needs create. It's a silly name. The same could be said about in the same type of situation, I can't override new in the subclass? That's wrong IMHO. There should never be a situation where I can't provide my own new(). And I don't really think and SUPER class methods calling new on itself or it's subclass is quite kosher either; but it happens.

  • Comment on Re^4: A Growing Dislike for SQL-OOP Mappers

Replies are listed 'Best First'.
Re^5: A Growing Dislike for SQL-OOP Mappers
by perrin (Chancellor) on Aug 22, 2005 at 23:16 UTC
    There's nothing special about new() in Perl -- it's the same as any other method. You can override it, and you will have the same trials and tribulations with overriding it that you would have with any other inheritance scenario. It still sounds like you're complaining that you don't like OOP to me.
      Well, I think it's a real problem for the dispatcher not to know the difference between abstract interface methods and infrastructural methods, which is why Perl 6 introduces the concept of "submethods" that are callable from outside the class, but only if there's an exact type match on the invocant. Otherwise the dispatcher keeps looking for a more appropriate method or submethod to dispatch to.

      (There's also the concept of completely private methods that aren't visible from outside the class at all, but that's really a different beastie altogether.) Anyway, I think use of submethods would probably solve the first problem of the OP.

Re^5: A Growing Dislike for SQL-OOP Mappers
by itub (Priest) on Aug 22, 2005 at 22:28 UTC
    I never said "don't override it", I even proposed two ways you could do it! This is a general situation: if you want to override method A so that it calls method B, and you know that method B will call method A, you can fix the loop by overriding method B. For example,
    package MyApp::DBI; use base 'Class::DBI'; __PACKAGE__->connection(...); 1; package MyApp::Gallery; use base 'MyApp::DBI'; __PACKAGE__->table('galleries'); __PACKAGE__->columns(...); sub create { my ($self, $ops) = @_; my $dir = $ops->{'directory'}; if (-e $dir) { die 'directory exists'; else { mkdir $directory; $self->find_or_create($data); }; return; }; sub find_or_create { my $class = shift; my $hash = ref $_[0] eq "HASH" ? shift: {@_}; my ($exists) = $class->search($hash); return defined($exists) ? $exists $class->SUPER::create($hash) +; } 1;

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://485776]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (1)
As of 2022-01-27 00:44 GMT
Find Nodes?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:

    Results (70 votes). Check out past polls.