.\" Automatically generated by Pod::Man 2.22 (Pod::Simple 3.07) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is turned on, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .ie \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . nr % 0 . rr F .\} .el \{\ . de IX .. .\} .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "Historical 3pm" .TH Historical 3pm "2011-04-27" "perl v5.10.1" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Cache::Historical \- Cache historical values .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& use Cache::Historical; \& \& my $cache = Cache::Historical\->new(); \& \& # Set a key\*(Aqs value on a specific date \& $cache\->set( $dt, $key, $value ); \& \& # Get a key\*(Aqs value on a specific date \& my $value = $cache\->get( $dt, $key ); \& \& # Same as \*(Aqget\*(Aq, but if we don\*(Aqt have a value at $dt, but we \& # do have values for dates < $dt, return the previous \& # historic value. \& $cache\->get_interpolated( $dt, $key ); .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" Cache::Historical caches historical values by key and date. If you have something like historical stock quotes, for example .PP .Vb 4 \& 2008\-01\-02 msft 35.22 \& 2008\-01\-03 msft 35.37 \& 2008\-01\-04 msft 34.38 \& 2008\-01\-07 msft 34.61 .Ve .PP then you can store them in Cache::Historical like .PP .Vb 1 \& my $cache = Cache::Historical\->new(); \& \& my $fmt = DateTime::Format::Strptime\->new( \& pattern => "%Y\-%m\-%d"); \& \& $cache\->set( $fmt\->parse_datetime("2008\-01\-02"), "msft", 35.22 ); \& $cache\->set( $fmt\->parse_datetime("2008\-01\-03"), "msft", 35.37 ); \& $cache\->set( $fmt\->parse_datetime("2008\-01\-04"), "msft", 34.38 ); \& $cache\->set( $fmt\->parse_datetime("2008\-01\-07"), "msft", 34.61 ); .Ve .PP and retrieve them later by date: .PP .Vb 1 \& my $dt = $fmt\->parse_datetime("2008\-01\-03"); \& \& # Returns 35.37 \& my $value = $cache\->get( $dt, "msft" ); .Ve .PP Even if there's no value available for a given date, but there are historical values that predate the requested date, \f(CW\*(C`get_interpolated()\*(C'\fR will return the next best historical value: .PP .Vb 1 \& my $dt = $fmt\->parse_datetime("2008\-01\-06"); \& \& # Returns undef, no value available for 2008\-01\-06 \& my $value = $cache\->get( $dt, "msft" ); \& \& # Returns 34.48, the value for 2008\-01\-04, instead. \& $value = $cache\->get_interpolated( $dt, "msft" ); .Ve .SS "Methods" .IX Subsection "Methods" .IP "\fInew()\fR" 4 .IX Item "new()" Creates the object. Takes the SQLite file to put the date into as an additional parameter: .Sp .Vb 3 \& my $cache = Cache::Historical\->new( \& sqlite_file => "/tmp/mydata.dat", \& ); .Ve .Sp The SQLite file defaults to .Sp .Vb 1 \& $HOME/.cache\-historical/cache\-historical.dat .Ve .Sp so if you have multiple caches, you need to use different SQLite files. .IP "\fItime_range()\fR" 4 .IX Item "time_range()" .Vb 2 \& # List the time range for which we have values for $key \& my($from, $to) = $cache\->time_range( $key ); .Ve .IP "\fIkeys()\fR" 4 .IX Item "keys()" .Vb 2 \& # List all keys \& my @keys = $cache\->keys(); .Ve .IP "\fIvalues()\fR" 4 .IX Item "values()" .Vb 3 \& # List all the values we have for $key, sorted by date \& # ([$dt, $value], [$dt, $value], ...) \& my @results = $cache\->values( $key ); .Ve .IP "\fIclear()\fR" 4 .IX Item "clear()" .Vb 2 \& # Remove all values for a specific key \& $cache\->clear( $key ); \& \& # Clear the entire cache \& $cache\->clear(); .Ve .IP "\fIlast_update()\fR" 4 .IX Item "last_update()" .Vb 2 \& # Return a DateTime object of the last update of a given key \& my $when = $cache\->last_update( $key ); .Ve .IP "\fIsince_last_update()\fR" 4 .IX Item "since_last_update()" .Vb 3 \& # Return a DateTime::Duration object since the time of the last \& # update of a given key. \& my $since = $cache\->since_last_update( $key ); .Ve .SH "LEGALESE" .IX Header "LEGALESE" Copyright 2007\-2011 by Mike Schilli, all rights reserved. This program is free software, you can redistribute it and/or modify it under the same terms as Perl itself. .SH "AUTHOR" .IX Header "AUTHOR" 2007, Mike Schilli