[Fwd: [Fwd: Re: Phoenix.pm: Inheriting from DateTime]]

Douglas E. Miles doug at phoenixinternet.com
Thu Feb 19 18:12:41 CST 2004


I'm forwarding this for eden, because majordomo didn't like the "sub" in
"Sub new".  I turned off this (mis)feature.  I should have done this a
long time ago.  Hopefully we'll have fewer legitimate emails bouncing.
We now return to your regularly scheduled email...


Hmmm... I think there might be a way for you to turn off warnings for a
certain block.  It's been such a long time since I touched Perl (oh how
I miss'er), but... maybe...

sub new
{
     my $package = shift;
     my $class = ref($package) || $package;

     {
       local ($SIG{'__WARN__'}) = sub {};
       my $self = $class->SUPER::new(@_);
     }
     bless($self, $class);

     return $self;
}

Actually, I tested this, so it won't send out that warning.

The only problem I see with this is that DateTime->new()'s legitimate
warnings would go unheard.

Hope this was helpful......

eden

Douglas E. Miles wrote:
> I'm trying to create a sub-class of DateTime.  I want to pass a few new 
> attributes in the constructor.  DateTime validates the parameters passed 
> to new(), so I can't just pass my new()s @_.  I have a few ideas about 
> how to handle this, but none seem particularly elegant.  Any thoughts on 
> how to approach this?  Here is that code that doesn't work, just to give 
> you an idea:





More information about the Phoenix-pm mailing list