# -*- cperl -*- # ----------------------------------------------------------------------------- package POE::Component::IRC::Plugin::NoPaste::StaticFile; use strict; use warnings; use File::Spec; use File::stat; require Exporter; our @ISA = qw(Exporter); our @EXPORT = qw(&static_file); # path => [lastmod, content] my $TABLE = {}; sub static_file { my ($path) = @_; my $fullpath; foreach my $inc (@INC) { my $fpath = File::Spec->canonpath( File::Spec->catdir( File::Spec->splitdir($inc), qw(POE Component IRC Plugin NoPaste), File::Spec->splitdir($path))); if (-r $fpath) { $fullpath = $fpath; last; } } defined $fullpath or return undef; my $lastmod = stat($fullpath)->mtime; my $entry = $TABLE->{$fullpath}; if (!$entry or $entry->[0] < $lastmod) { local $/ = undef; open my $fh, '<', $fullpath; my $content = <$fh>; close $fh; $entry = $TABLE->{$fullpath} = [$lastmod, $content]; } return $entry->[1]; } 1;