> -----Original Message----- > From: perig...@gmail.com [mailto:perig...@gmail.com] On Behalf Of Chris > Prather > Sent: Saturday, January 22, 2011 1:04 PM > To: Stevan Little > Cc: Rick Apichairuk; Nick Perez; moose@perl.org > Subject: Re: Inheritance not working for some weird reason. > > On Sat, Jan 22, 2011 at 3:40 PM, Stevan Little > <stevan.lit...@iinteractive.com> > wrote: > > Quick disclaimer: I don't use MooseX::Declare personally and I never > > have, the level of sugar never appealed to me. That said .... > > > > Honestly, I think the answer is to stop using MooseX::Declare. > > > > After I saw your nopaste on #moose last night, I was looking over > > MX::Declare and noticed that no major work has really been done on it > > in over a year. It is and has always been *highly* experimental and it > > is only recommend for production use if you are willing to deal with > > some of it's fragility and odd edge cases. > > Although I don't use MooseX::Declare either, and agree with your > sentiments. The problem isn't MooseX::Declare in this case. > > Because I apparently have nothing better to do with my Saturday afternoon, > I spent 30 minutes cleaning up the code so that I could actually run it as > separate files. The code split out is available in this gist: > https://gist.github.com/dedc59a759c2183c418b > > Once I got the code so I could see what was going on, removed the calls to > code that wasn't provided. I discovered the following. The tests assume that > $manager->Hire($person) do the following: > > > my $employee = $manager->Hire($person); > > isa_ok( $employee, $class_person ); > isa_ok( $employee, $class_employee ); > > cmp_ok( $employee->name, 'eq', 'Jack Smith', 'BAD' ); > cmp_ok( $employee->alias, 'eq', 'Jackie', 'BAD' ); > cmp_ok( $employee->dateOfBirth, 'eq', '07/17/1980', 'BAD' ); > > > However the code for the Hire method is defined like so: > > method Hire (Person $person!) { > # THIS IS BROKEN!!!! > my $employee = Employee->new( > name => 'Bill Gates', > alias => 'Mr Evil', > dateOfBirth => '05/27/1965', > hireDate => '01/01/2010', > ); > > # the object returned ISA Person and Employee but has none of the > Person attributes! > die unless $employee->isa('Person'); > die unless $employee->isa('Employee'); > > #print Dumper($employee); > > return $employee; > } > } > > > That is it *always* returns an instance of Employee who is Bill Gates. > Um. I have no clue how inheritance would make this any different. > Non-working code is non-working. > > -Chris
Chris, First of all, please accept my deepest apologies for upsetting you. I'm cutting off my left pinky right now. Where would you like it shipped to? The original code did actually take the $person object and instantiate an employee object using the attributes from $person and then generating the current date for the hireDate attribute. In trying to debug the problem, I tried to get the Employee class to instantiate correctly from within the Manager class. That is why it is hard coded there. I forgot about that and should have adjusted it. When I dumped out the contents of $employee, the person attributes are always missing. And that is what I was referring to when I said inheritance was now working. My apologies for leaving that in there. I think I will stop using MooseX::Declare for now. Thanks for your time and help. Rick