On Thu, 2 Sep 2004, Rick Measham wrote:
> On 2 Sep 2004, at 2:51 PM, Rick Measham wrote:
> > It'd be really ugly to do stuff like:
> > $dt = $strptime->parse_datetime( $string, asa => 'My::DateTime' );
>
> But we could do something similar with just a change in DateTime
> itself. We have a 'from_object' constructor -- How about adding an
> 'asa' method. (I call it asa because it's like isa)
>
> $my_datetime =
> $strptime->parse_datetime($string)->asa('My::DateTime');
>
> Then in DateTime.pm:
>
> sub asa {
> my ($self, $class) = @_;
>
> eval { require $class };
> die($@) if $@;
>
> eval { my $newself = $class->from_object( $self ) }
> die("$class is unable to accept a DateTime: $@") if $@ or not
> defined $newself;
>
> return $newself;
> }
Well, the original question was in regards to subclasses of DateTime.pm.
Given that a subclass will inherit from_object(), that seems good enough.
my $my_dt = My::DT::Subclass->from_object( object => DateTime->new );
That should work without any changes to existing code.
It's a little ugly, though it may be better than passing around a class
param to ever DT::Format object/class.
And it could easily encapsulated a "my_dt()" sub or something.
-dave
/*=======================
House Absolute Consulting
www.houseabsolute.com
=======================*/