Apache2-PageKit
view release on metacpan or search on metacpan
lib/Apache2/PageKit.pm view on Meta::CPAN
$output_param_object->param('pkit_view:' . $pkit_view => 1);
}
return OK;
}
sub _send_static_file {
my ( $pk, $filename ) = @_;
my $apr = $pk->{apr};
my $file_mtime = (stat($filename))[9];
my $ims = $apr->headers_in->{'If-Modified-Since'};
if ( $ims ) {
my $t = APR::Date::parse_http($ims);
if ( $t && $file_mtime <= $t ) {
return HTTP_NOT_MODIFIED;
}
}
# renamed back to ht_time in mod_perl 1.9913
# $apr->headers_out->{'Last-Modified'} = Apache2::Util::format_time($file_mtime, '%a, %d %b %Y %H:%M:%S %Z', 1, $apr->pool );
$apr->headers_out->{'Last-Modified'} = Apache2::Util::ht_time( $apr->pool, $file_mtime );
lib/Apache2/PageKit/Content.pm view on Meta::CPAN
($COMPONENT_ID_DIR = $component_id) =~ s![^/]*$!!;
$INCLUDE_MTIMES = $content->{include_mtimes};
# XSLT file
my $xml_file = "$content->{content_dir}/$component_id.xml";
unless(-f $xml_file){
die "Cannot find xml file $content->{content_dir}/$component_id.xml or
template file $pkit_view/$component_id.tmpl";
}
# my $xml_mtime = (stat($xml_file))[9];
# $INCLUDE_MTIMES->{$xml_file} = $xml_mtime;
my $parser = XML::LibXML->new( ext_ent_handler => \&open_uri );
# call backs so that we can note the mtimes of dependant files
$parser->match_callback(\&match_uri);
$parser->open_callback(\&open_uri);
$parser->close_callback(\&close_uri);
$parser->read_callback(\&read_uri);
my $xp = $parser->parse_file("/$component_id.xml");
lib/Apache2/PageKit/Content.pm view on Meta::CPAN
my ($stylesheet_href) = ($pi_str =~ m!href="([^"]*)"!);
push @stylesheet_hrefs, $stylesheet_href;
}
# for now, just use first stylesheet... we'll add multiple stylesheets later
unless ($stylesheet_hrefs[0]){
die qq{must specify <?xml-stylesheet href="file.xsl"?> in $xml_file};
}
my $stylesheet_file = $stylesheet_hrefs[0];
# my $stylesheet_mtime = (stat(_))[9];
# $INCLUDE_MTIMES->{$stylesheet_file} = $stylesheet_mtime;
my $stylesheet_parser = XML::LibXML->new();
my $stylesheet_xp = $stylesheet_parser->parse_file($stylesheet_file);
# for caching pages including the params info (that way extrenous parameters
# won't be taken into account when counting)
# META: do i only need to cache top level params from top level stylesheet?
for my $node ($stylesheet_xp->findnodes(q{node()[name() = 'xsl:stylesheet']/node()[name() = 'xsl:param']})->get_nodelist){
my $param_name = $node->getAttribute('name');
$Apache2::PageKit::Content::PAGE_ID_XSL_PARAMS->{$PAGE_ID}->{$param_name} = 1;
lib/Apache2/PageKit/Content.pm view on Meta::CPAN
}
sub open_uri {
my $uri = shift;
my $abs_uri = _rel2abs($uri);
open my $xml, "$abs_uri" or die "XML file $abs_uri doesn't exist";
binmode $xml;
local($/) = undef;
my $xml_str = <$xml>;
close $xml;
my $mtime = (stat(_))[9];
$INCLUDE_MTIMES->{$abs_uri} = $mtime;
# we avoid to use any XML::LibXML parser inside the callbackroutines.
return $xml_str;
}
sub read_uri {
return substr($_[0], 0, $_[1], "");
}
lib/Apache2/PageKit/View.pm view on Meta::CPAN
binmode $fh;
# read mtime from first line
chomp($gzip_mtime = <$fh>);
# read rest of gzipped content
local $/;
$gzipped_content = <$fh>;
close $fh;
if($view->{reload} ne 'no'){
# is the cache entry valid or changed on disc?
my $mtime = ( stat($filename) )[9];
if($mtime != $gzip_mtime){
$gzipped_content = $view->_create_static_zip($filename, $gzipped_filename);
}
}
} else {
$gzipped_content = $view->_create_static_zip($filename, $gzipped_filename);
}
return $gzipped_content;
}
lib/Apache2/PageKit/View.pm view on Meta::CPAN
$view->_html_clean(\$content);
my $gzipped_content = Compress::Zlib::memGzip($content);
(my $gzipped_dir = $gzipped_filename) =~ s!(/)?[^/]*?$!!;
File::Path::mkpath("$gzipped_dir");
if ($gzipped_content) {
my $mtime = (stat($filename))[9];
if ( open my $gzip_fh, ">$gzipped_filename" ) {
binmode $gzip_fh;
print $gzip_fh "$mtime\n";
print $gzip_fh $gzipped_content;
close $gzip_fh;
} else {
warn "can not create gzip cache file $view->{cache_dir}/$gzipped_filename: $!";
}
return $gzipped_content;
}
lib/Apache2/PageKit/View.pm view on Meta::CPAN
# first check timestamps
my $include_mtimes = $record->{include_mtimes};
while (my ($filename, $cache_mtime) = each %$include_mtimes){
# check if file still exists
unless(-f "$filename"){
return 0;
}
# check if file is up to date
my $file_mtime = (stat($filename))[9];
# print "hi $filename - $cache_mtime - $file_mtime<br>";
if($file_mtime != $cache_mtime){
return 0;
}
if($filename =~ m!^$view->{view_dir}/Default/! && $pkit_view ne 'Default'){
# check to see if any new files have been uploaded to the $pkit_view dir
(my $check_filename = $filename) =~ s!^$view->{view_dir}/Default/!$view->{view_dir}/$pkit_view/!;
if (-f "$check_filename"){
return 0;
lib/Apache2/PageKit/View.pm view on Meta::CPAN
binmode $template_fh, ":encoding($default_input_charset)";
local $/;
my $template = <$template_fh>;
close $template_fh;
# expand PKIT_MACRO tags
$template =~ s!<\s*PKIT_MACRO$key_value_pattern\s*/?>!$component_params->{uc($+)} || ''!egi;
$template_ref = \$template;
my $mtime = (stat(_))[9];
$view->{include_mtimes}->{$template_file} = $mtime;
}
if($view->{can_edit} eq 'yes'){
Apache2::PageKit::Edit::add_component_edit_stubs($view, $page_id, $template_ref, $pkit_view);
}
$view->_include_components($page_id,$template_ref,$pkit_view);
return $template_ref;
lib/Apache2/PageKit/View.pm view on Meta::CPAN
template_class => $view->{template_class},
);
$view->{lang_tmpl} = $content->{lang_tmpl} = {};
$content->{include_mtimes} = {};
$view->{component_ids_hash} = {};
# we add Config.xml to the hash of files to be checked for mtimes,
# in case default_input_charset or default_output_charset changes!
(my $config_file = $view->{view_dir}) =~ s!/View$!/Config/Config.xml!;
my $config_mtime = ( stat($config_file) )[9];
$view->{include_mtimes} = {$config_file => $config_mtime};
my $template_file = $view->_find_template($pkit_view, $page_id);
my $template_ref = $view->_load_component($page_id,$page_id,$pkit_view);
# remove PKIT_COMMENT parts.
my $pkit_comment_re = $re_helper{ $view->{relaxed_parser} eq 'yes' ? 'relaxed_parser' : 'std_parser' }->{pkit_comment_re};
$$template_ref =~ s/$pkit_comment_re//sgi;
# my $template_file = $view->_find_template($pkit_view, $page_id);
lib/Apache2/PageKit/View.pm view on Meta::CPAN
template_class => $content_template_class,
);
$view->{lang_tmpl} = $content->{lang_tmpl} = {};
$content->{include_mtimes} = {};
$view->{component_ids_hash} = {};
# we add Config.xml to the hash of files to be checked for mtimes,
# in case default_input_charset or default_output_charset changes!
( my $config_file = $view->{view_dir} ) =~ s!/View$!/Config/Config.xml!;
my $config_mtime = ( stat($config_file) )[9];
$view->{include_mtimes} = { $config_file => $config_mtime };
my $template_file = $view->_find_template( $pkit_view, $page_id );
my $template_ref = $view->_load_component( $page_id, $page_id, $pkit_view );
# remove PKIT_COMMENT parts.
my $pkit_comment_re = $re_helper{ $view->{relaxed_parser} eq 'yes' ? 'relaxed_parser' : 'std_parser' }->{pkit_comment_re};
$$template_ref =~ s/$pkit_comment_re//sgi;
# my $template_file = $view->_find_template($pkit_view, $page_id);
( run in 1.026 second using v1.01-cache-2.11-cpan-49f99fa48dc )