Phoenix.pm: Inheriting from DateTime
Douglas E. Miles
doug at phoenixinternet.com
Thu Feb 19 15:10:31 CST 2004
Scott Walters wrote:
> Hi Doug,
>
> Looks like you're going down a good road right now. Just have to go a little
> further.
>
>
>>sub new
>>{
>>
>> my $package = shift;
>> my $class = ref($package) || $package;
>
>
> my %params = @_;
> my $event_name = delete $param{event_name};
>
>
>> # my $self = $class->SUPER::new(@_);
>
> my $self = $class->SUPER::new(%params);
>
>
>> bless($self, $class);
>
>
> $self->{event_name} = $event_name; # ram it in there forceibly
>
>
>> return $self;
>>
>>} # END: new
>
>
> That's kind of ugly, between reblessing the object, stripping off unexpected
> parameters, and then mashing them into the object. I don't know of a better
> way to do this, though.
<SNIP>
Thanks Scott. That was exactly the approach I was going to take. I
agree that its ugly. I was hoping I was missing something obvious. I
guess that's what I'll do unless someone else comes up with a better
idea. All my inheritance experience involves my own classes, so I've
never run into this before.
More information about the Phoenix-pm
mailing list