Created
December 1, 2010 15:50
-
-
Save wchristian/723669 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use strict; | |
use warnings; | |
package Date::Calc::Cached; | |
our ( @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS, %old ); | |
use base 'Exporter'; | |
use Date::Calc (); | |
BEGIN { | |
$old{$_} = \&{$_} for qw( Date::Calc::PP::DateCalc_check_date Date::Calc::PP::DateCalc_Date_to_Days ); | |
} | |
my @cached = qw( Delta_Days ); | |
my %cached = map { $_ => 1 } @cached; | |
@EXPORT = @Date::Calc::EXPORT; | |
@EXPORT_OK = @Date::Calc::EXPORT_OK; | |
%EXPORT_TAGS = ( all => \@EXPORT_OK ); | |
my @to_import = ( @EXPORT, @EXPORT_OK ); | |
@to_import = grep { !$cached{$_} } @to_import; | |
Date::Calc->import( @to_import ); | |
my %cache_Delta_Days; | |
sub Delta_Days { | |
return $cache_Delta_Days{"@_"} ||= Date::Calc::Delta_Days(@_); | |
} | |
{ | |
no warnings 'redefine'; | |
my %cache_check_date; | |
sub Date::Calc::PP::DateCalc_check_date { | |
return $cache_check_date{"@_"} ||= $old{'Date::Calc::PP::DateCalc_check_date'}->(@_); | |
} | |
my %cache_Date_to_Days; | |
sub Date::Calc::PP::DateCalc_Date_to_Days { | |
return $cache_Date_to_Days{"@_"} ||= $old{'Date::Calc::PP::DateCalc_Date_to_Days'}->(@_); | |
} | |
} | |
1; | |
__END__ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment