Apache2-SSI

 view release on metacpan or  search on metacpan

META.json  view on Meta::CPAN

      "configure" : {
         "requires" : {
            "ExtUtils::MakeMaker" : "0"
         }
      },
      "runtime" : {
         "requires" : {
            "Apache::Test" : "0",
            "Config" : "0",
            "Cwd" : "0",
            "DateTime" : "0",
            "DateTime::Format::Strptime" : "0",
            "Digest::MD5" : "0",
            "Digest::SHA" : "0",
            "Encode" : "0",
            "File::Basename" : "0",
            "File::Spec" : "3.26",
            "File::Which" : "0",
            "HTML::Entities" : "0",
            "IO::File" : "0",
            "JSON" : "0",
            "MIME::Base64" : "0",

META.yml  view on Meta::CPAN

  version: '1.4'
name: Apache2-SSI
no_index:
  directory:
    - t
    - inc
requires:
  Apache::Test: '0'
  Config: '0'
  Cwd: '0'
  DateTime: '0'
  DateTime::Format::Strptime: '0'
  Digest::MD5: '0'
  Digest::SHA: '0'
  Encode: '0'
  File::Basename: '0'
  File::Spec: '3.26'
  File::Which: '0'
  HTML::Entities: '0'
  IO::File: '0'
  JSON: '0'
  MIME::Base64: '0'

Makefile.PL  view on Meta::CPAN

        'strict'        => 0,
        'warnings'      => 0,
        'parent'        => 0,
        'vars'          => 0,
        'version'       => 0,
        'Config'        => 0,
        'Cwd'           => 0,
        # Not required to function
        # 'Apache2::Const'=> '2.000011',
        # 'Apache2::RequestRec' => '2.000011',
        'DateTime'      => 0,
        'DateTime::Format::Strptime' => 0,
        'Digest::MD5'   => 0,
        'Digest::SHA'   => 0,
        'Encode'        => 0,
        'File::Basename'=> 0,
        'File::Spec'    => '3.26',
        'File::Which'   => 0,
        'HTML::Entities'=> 0,
        'IO::File'      => 0,
        'JSON'          => 0,
        'MIME::Base64'  => 0,

lib/Apache2/SSI.pm  view on Meta::CPAN


sub _format_time
{
    my( $self, $time, $format, $tzone ) = @_;
    my $env = $self->env;
    $format ||= $self->{timefmt};
    # Quotes are important as they are used to stringify overloaded $time
    my $params = { epoch => "$time" };
    $params->{time_zone} = ( $tzone || 'local' );
    $params->{locale} = $env->{lang} if( length( $env->{lang} ) );
    require DateTime;
    require DateTime::Format::Strptime;
    my $tz;
    # DateTime::TimeZone::Local will die ungracefully if the local timezeon is not set with the error:
    # "Cannot determine local time zone"
    local $@;
    # try-catch
    eval
    {
        require DateTime::TimeZone;
        $tz = DateTime::TimeZone->new( name => 'local' );
    };
    if( $@ )
    {
        $tz = DateTime::TimeZone->new( name => 'UTC' );
        warn( "Your system is missing key timezone components. Reverting to UTC instead of local time zone.\n" );
    }
    
    # try-catch
    my $rv = eval
    {
        my $dt = DateTime->from_epoch( %$params );
        if( length( $format ) )
        {
            my $fmt = DateTime::Format::Strptime->new(
                pattern => $format,
                time_zone => ( $params->{time_zone} || $tz ),
                locale => $dt->locale->code,
            );
            $dt->set_formatter( $fmt );
            return( $dt );
        }
        else
        {
            return( $dt->format_cldr( $dt->locale->date_format_full ) );
        }
    };
    if( $@ )
    {
        $self->error( "An error occurred getting a DateTime object for time \"$time\" with format \"$format\": $@" );
        return( $self->errmsg );
    }
    return( $rv );
}

sub _handle_ifs
{
    my $self = shift( @_ );
    my $cond = shift( @_ );
    

lib/Apache2/SSI/Finfo.pm  view on Meta::CPAN

package Apache2::SSI::Finfo;
BEGIN
{
    use strict;
    use warnings;
    use warnings::register;
    use parent qw( Module::Generic );
    use vars qw( $VERSION $AUTOLOAD %EXPORT_TAGS @EXPORT_OK $ERROR );
    use Apache2::SSI::File::Type;
    use Exporter qw( import );
    use DateTime;
    use DateTime::Format::Strptime;
    use File::Basename ();
    our( $AUTOLOAD, $ERROR );
    use overload (
        q{""}    => sub    { $_[0]->{filepath} },
        bool     => sub () { 1 },
        fallback => 1,
    );
    if( exists( $ENV{MOD_PERL} ) )
    {
        require APR::Pool;

lib/Apache2/SSI/Finfo.pm  view on Meta::CPAN

sub _datetime
{
    my $self = shift( @_ );
    my $t = shift( @_ );
    return( $self->error( "No epoch time was provided." ) ) if( !length( $t ) );
    return( $self->error( "Invalid epoch time provided \"$t\"." ) ) if( $t !~ /^\d+$/ );
    local $@;
    # try-catch
    my $rv = eval
    {
        my $dt = DateTime->from_epoch( epoch => $t, time_zone => 'local' );
        my $fmt = DateTime::Format::Strptime->new(
            pattern => '%s',
            time_zone => 'local',
        );
        $dt->set_formatter( $fmt );
        return( Apache2::SSI::Datetime->new( $dt ) );
    };
    if( $@ )
    {
        return( $self->error( "Unable to get the datetime object for \"$t\": $@" ) );
    }

lib/Apache2/SSI/Finfo.pm  view on Meta::CPAN

    }
    return( $self->{error} || $ERROR );
}

AUTOLOAD
{
    my( $method ) = our $AUTOLOAD =~ /([^:]+)$/;
    no overloading;
    my $self = shift( @_ );
    my $class = ref( $self ) || $self;
    die( "DateTime object is gone !\n" ) if( !ref( $self->{dt} ) );
    my $dt = $self->{dt};
    if( $dt->can( $method ) )
    {
        return( $dt->$method( @_ ) );
    }
    else
    {
        return( $self->error( "No method \"$method\" available in DateTime" ) );
    }
};

1;
# NOTE: POD
__END__

=encoding utf-8

=head1 NAME

lib/Apache2/SSI/Finfo.pm  view on Meta::CPAN

=head1 SYNOPSIS

    my $finfo = Apache2::SSI::Finfo->new( '/some/file/path.html' );
    # or with Apache
    use Apache2::RequestRec ();
    use apache2::RequestUtil ();
    my $r = Apache2::RequestUtil->request;
    my $finfo = Apache2::SSI::Finfo->new( '/some/file/path.html', apache_request => $r );
    # Direct access to APR::Finfo
    my $apr = $finfo->apr_finfo;
    # Get access time as a DateTime object
    $finfo->atime;
    # Block site
    $finfo->blksize;
    # Number of blocks
    $finfo->blocks;
    if( $finfo->can_read )
    {
        # Do something
    }
    # Can also use
    $finfo->can_write;
    $finfo->can_exec;
    $finfo->csize;
    # Inode change time as a DateTime object
    $finfo->ctime;
    $finfo->dev;
    if( $finfo->exists )
    {
        # Do something
    }
    print "File path is: ", $finfo->filepath;
    if( $finfo->filetype == Apache2::SSI::Finfo::FILETYPE_NOFILE )
    {
        # File does not exist

lib/Apache2/SSI/Finfo.pm  view on Meta::CPAN

When running under Apache mod_perl this is set automatically from the special L</handler> method, such as:

    my $r = $f->r; # $f is the Apache2::Filter object provided by Apache

=head2 apr_finfo

Sets or gets the L<APR::Finfo> object when running under Apache/mod_perl. Note that this value might be empty if the file does not exist. This is mentioned here for completeness only.

=head2 atime

Returns the file last access time as a L<Apache2::SSI::Datetime> object, which stringifies to its value in second since epoch. L<Apache2::SSI::Datetime> is just a wrapper around L<DateTime> to allow a L<DateTime> to be used in comparison with another...

For example:

    if( $finfo->atime > time() + 86400 )
    {
        print( "You are traveling in the future\n" );
    }

=head2 blksize

lib/Apache2/SSI/Finfo.pm  view on Meta::CPAN

=head2 can_execute

Returns true if the the effective user can execute the file. Same as L</exec>

=head2 csize

Returns the total size of file, in bytes. Same as L</size>

=head2 ctime

Returns the file inode change time as a L<Apache2::SSI::Datetime> object, which stringifies to its value in second since epoch. L<Apache2::SSI::Datetime> is just a wrapper around L<DateTime> to allow a L<DateTime> to be used in comparison with anothe...

=head2 dev

Returns the device number of filesystem. Same as L</dev>

=head2 device

Returns the device number of filesystem. Same as L</device>

=head2 exists

lib/Apache2/SSI/Finfo.pm  view on Meta::CPAN

    {
        print( "Owner can execute\n" );
    }
    if( $finfo->mode & 0001 )
    {
        print( "Everyone can execute too!\n" );
    }

=head2 mtime

Returns the file last modify time as a L<Apache2::SSI::Datetime> object, which stringifies to its value in second since epoch. L<Apache2::SSI::Datetime> is just a wrapper around L<DateTime> to allow a L<DateTime> to be used in comparison with another...

=head2 name

Returns the file base name. So if the file is C</home/john/www/some/file.html> this would return C<file.html>

Interesting to note that L<APR::Finfo/name> which is advertised as returning the file base name, actually returns just an empty string. With this module, this uses a workaround to provide the proper value. It use L<File::Basename/basename> on the val...

=head2 nlink

Returns the number of (hard) links to the file.

t/37.flastmod.t  view on Meta::CPAN

#!/usr/local/bin/perl
BEGIN
{
    use strict;
    use warnings;
    use Test::More qw( no_plan );
    use lib './lib';
    use vars qw( $BASE_URI $DEBUG );
    require( "./t/functions.pl" ) || BAIL_OUT( "Unable to find library \"functions.pl\"." );
    our $BASE_URI;
    use DateTime;
    use DateTime::Format::Strptime;
    our $DEBUG = exists( $ENV{AUTHOR_TESTING} ) ? $ENV{AUTHOR_TESTING} : 0;
};

use strict;
use warnings;

my( $inc_ts, $me_ts, $year );
local $@;
# try-catch
eval
{
    my $dt = DateTime->now( time_zone => 'local' );
    $year = $dt->year;
    my $inc = "./t/htdocs${BASE_URI}/include.01.txt";
    ## diag( "File $inc last modified time is ", $inc->stat->mtime, " (", scalar( localtime( $inc->stat->mtime ) ), ")." );
    $inc_ts = DateTime->from_epoch( epoch => (CORE::stat( $inc ))[9], time_zone => 'local' );
    my $params =
    {
        pattern => '%A %B %d, %Y',
        time_zone => 'local',
    };
    $params->{locale} = $ENV{lang} if( length( $ENV{lang} ) );
    my $fmt = DateTime::Format::Strptime->new( %$params );
    $inc_ts->set_formatter( $fmt );
    my $me = "./t/htdocs${BASE_URI}/07.03.flastmod.html";
    $me_ts = DateTime->from_epoch( epoch => (CORE::stat( $me ))[9], time_zone => 'local' );
    my $fmt2 = DateTime::Format::Strptime->new(
        pattern => '%D',
        time_zone => 'local',
        locale => 'en_US',
    );
    $me_ts->set_formatter( $fmt2 );
    diag( __FILE__, " last modification date time is '$me_ts'." ) if( $DEBUG );
};
if( $@ )
{
    BAIL_OUT( $@ );



( run in 0.405 second using v1.01-cache-2.11-cpan-05444aca049 )