Our apps (and the modules they use) use DateTime extensively.   We have the
need to do a lot of common operations on DateTime objects, for example
checking if a DateTime object is in the future.  So, I'm wondering what's
the recommended approach to provide these common methods.

I think what I'd do is add a method $dt->is_in_future, but I'm not clear how
we can subclass DateTime since "DateTime->new" is used directly in code we
don't control.

I could just 
stuff<http://markmail.org/message/pkyimhz5ufwla4ng#query:+page:1+mid:jqxwqrsz564eoimo+state:results>the
is_in_future() method into the DateTime namespace, or I could use
Class::Injection, for example.

The other approach is a utility module using Exporter[*] -- then do
 is_in_future( $dt ), but I'm not thrilled by that.

Or maybe use a Moose Role and bring in the method into where ever it's
needed and then do:

    $self->start_time_in_future;

Where:

   with 'My::DateTime::Util';

   sub start_time_in_future {
      my $self = shift;
      return $self->is_in_future( $self->start_time );
   }


But, of all of those I'd prefer to do $dt->is_in_future.   Is there a
recommend approach?

(Ok is_in_future is a bad example because it's so easy to write the check
directly.)


* This started out as a Moose question because I saw some code added to our
app that was using Moose Roles as an Exporter-replacement -- that is using
"with" to bring in the role but then calling the code as functions not as
methods.


Thanks,



-- 
Bill Moseley
[email protected]

Reply via email to