# -*- cperl -*-
# -----------------------------------------------------------------------------
# $Id: StaticFile.pm,v 1.1.1.1 2004/09/27 14:01:00 admin Exp $
# -----------------------------------------------------------------------------
package Celaenito::StaticFile;
use strict;
use warnings;
use File::Spec;
use File::stat;
require Exporter;
our @ISA = qw(Exporter);
our @EXPORT = qw(&static_file);

# パス => [最終更新日, 内容]
my $TABLE = {};

sub static_file {
    my ($path) = @_;
    $path = File::Spec->canonpath($path);
    return undef if !-r $path;

    my $lastmod = stat($path)->mtime;

    my $entry = $TABLE->{$path};
    if (!$entry or $entry->[0] < $lastmod) {
	local $/ = undef;
	open my $fh, '<', $path;
	my $content = <$fh>;
	close $fh;
	
	$entry = $TABLE->{$path} = [$lastmod, $content];
    }

    return $entry->[1];
}

1;
