Re: DateTime Performance

2003-08-09 Thread Eugene van der Pijll
John Siracusa schreef:
> Okay, here's a simple implementation of a memoized 
> DateTime::Locale::load().

A solution that is more or less equivalent, is to change the
DefaultLocale routine. At the moment, $DefaultLocale is saved as a
string; every time DT::new() is called without a "locale" argument, the
default locale is loaded again.

It should be a bit faster than your version, because DT::Locale::load is
never called in DT::new(). (Except if you specify another locale; in
that case you should pass the locale object, not the locale name, if you
want speed.)

Probably this changes the behaviour if the default locale is aliased.
But IMHO, that's probably for the better.

Probably this should happen with the timezone parameter as well: change

default => 'floating'

to

default => DateTime::TimeZone->new( name => 'floating' )

Eugene


Re: leap seconds in XS

2003-08-09 Thread Flavio S. Glock
Dave Rolsky wrote:
> 
> On Wed, 6 Aug 2003, Flavio S. Glock wrote:
> 
> > Dave Rolsky wrote:
> > >
> > > Ok, I did some benchmarks and it looks like date math involving leap
> > > seconds (basically an DateTime object where the time zone is _not_
> > > floating) has sped up about 10% or so, which is definitely a good thing.
> >
> > How about moving the pure-Perl DT::LeapSecond to DateTime.pm/ ?
> 
> Seems like a good idea.  Do you want to do it or should I?

Please do it (should we keep the tests?)

Please write something in the old POD about the move. 
I'll send a "last" version to CPAN after you update DateTime.

Thanks!
- Flavio S. Glock


[ANNOUNCE] DateTime::Format::Strptime 1.04

2003-08-09 Thread Rick Measham
This version fixes the Locale issue. It also fixes a couple of bugs I
hadn't noticed before.

It's up on CPAN, but it probably wont appear for a little while :)

Right now I have no website to upload it to so CPAN's where to get it.

Now I'm going to work out how to do this CVS thang with SourceForge.

Cheers!
Rick



Re: DT::Wrapper API/semantics

2003-08-09 Thread Rick Measham
On Sat, 2003-08-09 at 06:55, Dave Rolsky wrote:
> So what I think we really want is this:
> 
>   my $Wrapper = DT::Wrapper->wrapper( [$class1, $class2, $class3] );

Maybe my approach has some holes, but have a look at the attached and
see what you think ...

#!/usr/bin/perl

#---
package DateTime::AddOneDay;
#---

use DateTime;

# Calling new here gives us one day later than the args asked for.
sub new {
	my $class = shift;
	my $date = DateTime->new(@_)->add( days => 1);
	return bless $date, $class;
}

# Decorator's job is to add one day
sub add_one_day {
	return shift->add(days => 1);
}


#---
package DateTime::StrfPirate;
#---

# Only one thing here!
sub strftime {
	return "Your strftime method has been pirated by a decorator {evil laugh}.";
}


#---
package DateTime::Now;
#---

use DateTime;

# If now is called on this module we return DateTime->now() 
# .. figure that's what people would expect
sub new {
	my $class = shift;
	my %args = @_;
	# Trim out any params that will cause DateTime::now() to keel over
	my %useargs;
	$useargs{locale} = $args{locale} if $args{locale};
	$useargs{time_zone} = $args{time_zone} if $args{time_zone};
	# There must be a better way to do that!
	return bless DateTime->now(%useargs), $class;
}

# Decorator's real job is to set the time to the current time
sub setnow { 
	my $self = shift;
	my $now = DateTime->now();
	$self->set(
		hour => $now->hour,
		minute => $now->minute,
		second => $now->second,
		nanosecond => $now->nanosecond
	);
	return $self;
}


#---
package DateTime::Decorator;
#---

# called 'create' so that a call to 'new' calls the right new :)
sub create {
	my $class = shift;
	# Don't do Param::Validate because we've been passed all sort of
	# things depending on our decorator path
	my %args = @_;
	# Create our inheritance path. In the real solution, we'd check if
	# DateTime was already stated.
	@ISA = (@{delete $args{decorators}}, 'DateTime');
	# Bless nothing so we have something
	my $self = bless \{}, $class;
	# And now we have something we can create our object
	return bless $self->new(%args), $class;
}

sub decorate {
	# unshift more decorators onto @ISA
}

sub decorators {
	return @ISA;
}

#---
package main;
#---


my $datetime1 = DateTime::Decorator->create(
	decorators => ['DateTime::AddOneDay', 'DateTime::Now'],
	year => 2003,
	day => 12
);
print '$datetime1->datetime: ' . $datetime1->datetime . "\n";
print '$datetime1->setnow->datetime: ' . $datetime1->setnow->datetime . "\n\n";

my $datetime2 = DateTime::Decorator->create(
	decorators => ['DateTime::StrfPirate', 'DateTime::Now'],
	# no need for other constructors ..
	# ::StrfPirate has no new so we try the next decorator
	# ::Now has a new so it gets used .. and it doesn't need any params.
);
$datetime2->add(hours => 123);
print '$datetime2->datetime: ' . $datetime2->datetime . "\n";
print '$datetime2->setnow->datetime: ' . $datetime2->setnow->datetime . "\n";
print '$datetime2->strftime("%c"):   ' . $datetime2->strftime("%c") . "\n";



Re: DT::Wrapper API/semantics

2003-08-09 Thread Dave Rolsky
On Fri, 9 Aug 2003, Rick Measham wrote:

> On Sat, 2003-08-09 at 06:55, Dave Rolsky wrote:
> > So what I think we really want is this:
> >
> >   my $Wrapper = DT::Wrapper->wrapper( [$class1, $class2, $class3] );
>
> Maybe my approach has some holes, but have a look at the attached and
> see what you think ...

The big hole is that you set @ISA when you create the decorator, but what
if someone creates two _different_ decorators?  In that case you've just
broken the first one you made.

Also, we want to be able to use SUPER::foo inside the decorating classes.
For example, Josh's DT::Cache will obviously need to call it's parent's
new() method.

This means that we can't just use multiple inheritance, but instead we
need to create an actual chain of inheritance.


-dave

/*===
House Absolute Consulting
www.houseabsolute.com
===*/


Re: DT::Wrapper API/semantics

2003-08-09 Thread Joshua Hoblitt
> > Anyway, does this API sound sane?  And if it does, anyone have any really
> > clever implementation ideas?  I have some scary ones involved AUTOLOAD and
> > constructing classes on the fly.
>
> help me understand it -
> Does something like DT::Incomplete could be a wrapping class?

No.  This is the 'decorator infrastructure' that I've been whining for.  It's kind of 
a melting pot for 'add-ons' or 'plug-ins'.  The idea is to throw DT, DT::Cache, 
DT::Foo, DT::Validator, etc. into the 'pot' and end up with a factory that creates 
object with features from all of the input classes.

-J

--


Re: DateTime Performance

2003-08-09 Thread John Siracusa
On Tuesday, August 5, 2003, at 01:26 PM, Eugene van der Pijll wrote:
John Siracusa schreef:
Okay, here's a simple implementation of a memoized
DateTime::Locale::load().
A solution that is more or less equivalent, is to change the
DefaultLocale routine. [...]
Probably this changes the behaviour if the default locale is aliased.
But IMHO, that's probably for the better.
Yeah, that was my concern: add_aliases() and friends in 
DateTime::Locale would have to reach back into DateTime and blank the 
cached locale, which seemed evil to me.  But I was just thinking of 
preserving the existing behavior.  If this is not a constraint, then 
I'm all for the alternative you suggested.

-John



Re: DateTime used with Class::DBI

2003-08-09 Thread Iain Truskett
* Jean Forget ([EMAIL PROTECTED]) [08 Aug 2003 16:02]:

[...]
> Why not use subclassing?

Most of the other modules return DateTime objects rather
than MyDT objects.

Is there a good way to get all the various support modules
to return one's custom subclass without (a) subclassing all
of them, (b) reblessing the output, (c) having
MyDT->new_from_dt( $dt )?


cheers,
-- 
Iain.


Problem with DateTime::Calendar::Coptic

2003-08-09 Thread Jean Forget
I execute:

use DateTime;
use DateTime::Calendar::Coptic;
$day =  DateTime->now();
my $co = DateTime::Calendar::Coptic->from_object(object => $day);

and I get

Undefined subroutine &DateTime::Calendar::Coptic::validate called
at /home/p80/perl/lib/site_perl/5.8.0/DateTime/Calendar/Coptic.pm
line 73.

Maybe you should insert "use Params::Validate" in your module
and change the subroutine invocation in line 73 (I have not the
time to try it for the moment).

Jean Forget

-- 
And now we have the World Wide Web (the only thing I know of
whose shortened form --- www --- takes three times longer to say than
what it¹s short for).
  -- Douglas Adams, the Salmon of Doubt




Re: DateTime used with Class::DBI

2003-08-09 Thread Casey West
It was Thursday, August 07, 2003 when Matthew McGillis took the soap box, saying:
: 
: I'm not sure anyone is interested but I thought I would pass this 
: along. I have started using Class::DBI and was hoping I could also 
: use DateTime with it. Class::DBI has some hooks to allow for any type 
: of Object to represent Time. However the one limitation it has is 
: that you must be able to call a method with no parameters to produce 
: the proper output for the database. So the only way I could use 
: DateTime with it is if $datetime->somename() produces the correct 
: format for the database I'm using.

This is not true, you can also pass a code reference, any code
reference.

__PACKAGE__->has_a( time_stamp => 'DateTime',
inflate=> sub { ... },
deflate=> sub { ... },
  );

  Casey West

-- 
Shooting yourself in the foot with Assembly Language 
You try to shoot yourself in the foot only to discover you must first
reinvent the gun, the bullet, and your foot.