On Wed, 21 Dec 2005, Rick Measham wrote:
my $DateTimeGPS = DateTime::Decorated( with => 'GPS' );

Dave Rolsky wrote:
This means you're sticking a Decorated() function into the DateTime namespace. Is that intentional? It seems awfully weird.

Oops! My bad ..
my $DateTimeGPS = new DateTime::Decorated( with => 'GPS' );


There are a couple disadvantages to this approach:

* Sticking everything in one namespace (DateTime) can lead to name collisions.

So maybe:
   package DateTime::Extended::GPS;
   @ISA = qw/DateTime/;

Rather than decorating, we add an 'Extended' namespace. However this doesn't allow mixins that give us more than one extension at a time.

* Looking at the code, it's not clear that some of the methods that appear to be in that namespace are not available there normally. This makes it hard to look up docs, for example.

So .. we need to require decorations include a namespace in their methods:
   DateTime::Decorated::GPS::gps_*
but I hate that :)

I really wish we could come up with a cleaner way to get the same functionality. Most importantly, I wouldn't want this to be the _only_ way to do this. So if I want to construct a DateTime object from a year & week, I shouldn't have to create a new decorated class and do it that way.

Maybe split the whole thing up:

   %hash = DateTime::Util::GPS::gps2hash(
      week => 88, second => 22302
   );
   $dt = new DateTime( %hash );

That ::Util module can then be called by the ::Decorated module and also by the ::Extended module. That means there's just one main place to fix errors :)

The Decorated and Extended modules could even just auto-wrap the Util by looking for known entities:
   package DateTime::Util::GPS;
   sub constructor { DateTime->new( gps2hash( @_ ) ) }

   sub methods {(
      weeks => sub {
         (datetime2gps($_[0]))[0];
      }
      seconds => sub {
         (datetime2gps($_[0]))[1];
      }
   )}

Then Extended.pm looks for &constructor and &methods and make an DateTime::Extended::GPS namespace. Decorated looks for these methods and mixes them into DateTime with a gps_ prefix.

Maybe we even create a glue.pl that turns creates these links statically rather than dynamically... and would even create POD that tells the user to see the ::Util for the documentation.

Just thoughts.

Cheers!
Rick Measham

--
 "War is God's way of teaching Americans geography."
                             -- Ambrose Bierce

Reply via email to