Re: Annouce: DBIx::Class, a.k.a "taking the easy way out"

[prev] [thread] [next] [Date index for 2005/07/25]

From: Matt S Trout
Subject: Re: Annouce: DBIx::Class, a.k.a "taking the easy way out"
Date: 23:55 on 25 Jul 2005
On Mon, Jul 25, 2005 at 03:53:07PM -0700, Michael G Schwern wrote:
> On Mon, Jul 25, 2005 at 11:52:02PM +0100, Matt S Trout wrote:
> > > You're doomed.
> > 
> > And yet
> > 
> > matthewt@mccoy:DBIx-Class$ ls t/cdbi-t/
> > 01-columns.t      04-lazy.t         09-has_many.t  15-accessor.t  19-set_sql.t
> > 02-Film.t         06-hasa.t         11-triggers.t  16-reserved.t  98-failure.t
> > 03-subclassing.t  08-inheritcols.t  12-filter.t    18-has_a.t
> > 
> > and it happily passes all of them (bar a few redacted because I haven't used
> > quite the same implementation, and a fair chunk because I haven't figured
> > out what sort of iterator I want yet.
> > 
> > Anyway, doomed is what they called me when I dived into the cdbi internals
> > to add resultset caching to Sweet, and when I added prefetch. On the whole,
> > I think I like being doomed :)
> 
> Its a long term doomed.  DOOOOOOOOOOOOOOOOOOOOOOOOMED!  Multiple inheritance
> of unrelated classes is the sort of thing that lets you solve your problem
> now but trips you up later on down the road.
> 
> I thought multiple inheritance was a great idea and look at how long it 
> worked out fine before the cracks in CDBI started to show.
> 
> *RATTLING CHAINS* Learn from my fate!

The following script lets me analyze the chain of whatever method I need to
relatively easily; at some point I'll see about turning it into a compile
time checker or similar, but for the moment it does the trick just fine.

#!/usr/bin/perl

use strict;
use warnings;
use Class::ISA;

my $class = $ARGV[0];

die "usage: nextalyzer Some::Class" unless $class;

eval "use $class;";

die "Error using $class: $@" if $@;

my @path = reverse Class::ISA::super_path($class);

my %provided;
my %overloaded;

my @warnings;

foreach my $super (@path) {
  my $file = $super;
  $file =~ s/\:\:/\//g;
  $file .= '.pm';
  my $file_path = $INC{$file};
  die "Couldn't get INC for $file, super $super" unless $file_path;
  #warn "$super $file $file_path";
  open IN, '<', $file_path;
  my $in_sub;
  my $ws;
  my $uses_next;
  my @provides;
  my @overloads;
  while (my $line = <IN>) {
    unless ($in_sub) {
      ($ws, $in_sub) = ($line =~ /^(\s*)sub (\S+)/);
      next unless $in_sub;
    }
    if ($line =~ /^$ws\}/) {
      if ($uses_next) {
        push(@overloads, $in_sub);
      } else {
        push(@provides, $in_sub);
      }
      undef $in_sub;
      undef $uses_next;
      undef $ws;
      next;
    }
    $uses_next++ if ($line =~ /\-\>NEXT/);
  }
  close IN;
  foreach (@overloads) {
    push(@warnings, "Method $_ overloaded in $class but not yet provided")
      unless $provided{$_};
    push(@{$overloaded{$_}}, $super);
  }
  $provided{$_} = $super for @provides;
  print "Class $super:\n";
  print "Provides: @provides\n";
  print "Overloads: @overloads\n";
}

print "\n\n";

print join("\n", @warnings);

foreach my $o (keys %overloaded) {
  my $pr = $provided{$o} || "**NEVER**";
  print "Method $o: ".join(' ', reverse @{$overloaded{$o}})." ${pr}\n";
}

        -- 
             Matt S Trout           Website: http://www.shadowcatsystems.co.uk
  Technical Director        E-mail:  mst (at) shadowcatsystems.co.uk
Shadowcat Systems Ltd.

(message missing)

Re: Annouce: DBIx::Class, a.k.a "taking the easy way out"
Matt S Trout 23:55 on 25 Jul 2005

Delegation vs Hooks (was: Annouce: DBIx::Class, a.k.a "taking the easy way out")
=?ISO-8859-1?Q?Ask_Bj=F8rn_Hansen?= 23:27 on 26 Jul 2005

Generated at 16:36 on 28 Jul 2005 by mariachi v0.52