view release on metacpan or search on metacpan
use Apache2::SSI;
my $ssi = Apache2::SSI->new(
## If running outside of Apache
document_root => '/path/to/base/directory'
## Default error message to display when ssi failed to parse
## Default to [an error occurred while processing this directive]
errmsg => '[Oops]'
);
my $fh = IO::File->new( "</some/file.html" ) || die( "$!\n" );
$fh->binmode( ':utf8' );
my $size = -s( $fh );
my $html;
$fh->read( $html, $size );
$fh->close;
if( !defined( my $result = $ssi->parse( $html ) ) )
{
$ssi->throw;
};
print( $result );
use Apache2::SSI;
my $ssi = Apache2::SSI->new(
## If running outside of Apache
document_root => '/path/to/base/directory'
## Default error message to display when ssi failed to parse
## Default to [an error occurred while processing this directive]
errmsg => '[Oops]'
);
my $fh = IO::File->new( "</some/file.html" ) || die( "$!\n" );
$fh->binmode( ':utf8' );
my $size = -s( $fh );
my $html;
$fh->read( $html, $size );
$fh->close;
if( !defined( my $result = $ssi->parse( $html ) ) )
{
$ssi->throw;
};
print( $result );
lib/Apache2/SSI.pm view on Meta::CPAN
use Apache2::SSI;
my $ssi = Apache2::SSI->new(
# If running outside of Apache
document_root => '/path/to/base/directory'
# Default error message to display when ssi failed to parse
# Default to [an error occurred while processing this directive]
errmsg => '[Oops]'
);
my $fh = IO::File->new( "</some/file.html" ) || die( "$!\n" );
$fh->binmode( ':utf8' );
my $size = -s( $fh );
my $html;
$fh->read( $html, $size );
$fh->close;
if( !defined( my $result = $ssi->parse( $html ) ) )
{
$ssi->throw;
};
print( $result );
lib/Apache2/SSI/Common.pm view on Meta::CPAN
my $self = shift( @_ );
my $args = {};
no warnings 'uninitialized';
$args = Scalar::Util::reftype( $_[0] ) eq 'HASH'
? shift( @_ )
: !( scalar( @_ ) % 2 )
? { @_ }
: {};
my $file = $args->{filename} || $args->{file} || $self->filename;
return( $self->error( "No filename found." ) ) if( !length( $file ) );
my $binmode = $args->{binmode} // '';
local $@;
# try-catch
my $rv = eval
{
my $fh = IO::File->new( "<$file" ) ||
return( $self->error( "Unable to open file \"$file\" in read mode: $!" ) );
$fh->binmode( $binmode ) if( length( $binmode ) );
my $size;
if( $binmode eq ':unix' && ( $size = -s( $fh ) ) )
{
my $buf;
$fh->read( $buf, $size );
return( $buf );
}
else
{
local $/;
return( scalar( <$fh> ) );
}
lib/Apache2/SSI/Common.pm view on Meta::CPAN
sub slurp_utf8
{
my $self = shift( @_ );
my $args = {};
no warnings 'uninitialized';
$args = Scalar::Util::reftype( $_[0] ) eq 'HASH'
? shift( @_ )
: !( scalar( @_ ) % 2 )
? { @_ }
: {};
$args->{binmode} = ':utf8';
my $file = $args->{filename} || $args->{file} || $self->filename;
return( $self->error( "No filename found." ) ) if( !length( $file ) );
$args->{filename} = $file;
return( $self->slurp( $args ) );
}
1;
# NOTE: POD
__END__
lib/Apache2/SSI/Common.pm view on Meta::CPAN
$uri->query # foo=../bar
=head2 slurp
It returns the content of the L</filename>
it takes an hash reference of parameters:
=over 4
=item I<binmode>
my $content = $uri->slurp({ binmode => ':utf-8' });
=back
It will return undef and sets an L<Module::Generic/error> if there is no L</filename> value set or if the file cannot be opened.
=head2 slurp_utf8
It returns the content of the file L</filename> utf-8 decoded.
This is equivalent to:
my $content = $uri->slurp({ binmode => ':utf8' });
C<:utf8> is slightly a bit more lax than C<:utf-8>, so it you want strict utf8, you can do:
my $content = $uri->slurp({ binmode => ':utf-8' });
=head1 AUTHOR
Jacques Deguest E<lt>F<jack@deguest.jp>E<gt>
CPAN ID: jdeguest
L<https://gitlab.com/jackdeguest/Apache2-SSI>
=head1 SEE ALSO
lib/Apache2/SSI/File.pm view on Meta::CPAN
# would return /home/john/some/path assuming the file was /home/john/some/path/file.html
=head2 slurp
It returns the content of the L</filename>
it takes an hash reference of parameters:
=over 4
=item C<binmode>
my $content = $uri->slurp({ binmode => ':utf-8' });
=back
It will return undef and sets an L<Module::Generic/error> if there is no L</filename> value set or if the file cannot be opened.
=head2 slurp_utf8
It returns the content of the file L</filename> utf-8 decoded.
This is equivalent to:
my $content = $uri->slurp({ binmode => ':utf8' });
C<:utf8> is slightly a bit more lax than C<:utf-8>, so it you want strict utf8, you can do:
my $content = $uri->slurp({ binmode => ':utf-8' });
=head1 AUTHOR
Jacques Deguest E<lt>F<jack@deguest.jp>E<gt>
CPAN ID: jdeguest
L<https://gitlab.com/jackdeguest/Apache2-SSI>
=head1 SEE ALSO
lib/Apache2/SSI/File/Type.pm view on Meta::CPAN
my $path = File::Spec->catpath( File::Spec->tmpdir, $base . "_${checksum}.json" );
if( -e( $path ) && -s( $path ) )
{
$load_json_data->( $path ) || return;
}
else
{
return( $self->error( "Magic file provided \"$file\" does not exist." ) ) if( !-e( $file ) );
my $io = IO::File->new( "<$file" ) ||
return( $self->error( "Unable to open magic file provided \"$file\": $!" ) );
$io->binmode;
$self->parse_magic_file( $io );
$MAGIC_DATA = $self->{magic_data};
$io->close;
my $json = $self->as_json || return;
my $fh = IO::File->new( ">$path" ) ||
return( $self->error( "Unable to write to magic cache json data file \"$path\": $!" ) );
$fh->binmode;
$fh->print( $json );
$fh->close;
}
$MAGIC_DATA_SOURCE = $file_abs;
}
}
elsif( $MAGIC_DATA && scalar( @$MAGIC_DATA ) )
{
$self->{magic_data} = $MAGIC_DATA;
}
lib/Apache2/SSI/File/Type.pm view on Meta::CPAN
return( $json );
}
sub check
{
my $self = shift( @_ );
my $file = shift( @_ );
my $prev = $self->check_magic;
$self->check_magic( 1 );
my $io = IO::File->new( "<$file" ) || return( $self->error( "Unable to open magic file \"$file\": $!" ) );
$io->binmode;
$self->{magic}->{io} = $io;
my $data = [];
while( !$io->eof() )
{
$self->read_magic_entry( $data );
}
$io->close();
$self->dump( $data );
$self->check_magic( $prev );
return( $self );
lib/Apache2/SSI/File/Type.pm view on Meta::CPAN
sub dump
{
my $self = shift( @_ );
my $data = shift( @_ ) || $self->{magic_data};
my $depth = shift( @_ );
$data = [] unless( defined( $data ) );
$depth = 0 unless( defined( $depth ) );
our $err = IO::File->new;
$err->autoflush( 1 );
$err->fdopen( fileno( STDERR ), 'w' ) || return( $self->error( "Cannot write to STDERR: $!" ) );
$err->binmode;
foreach my $entry ( @$data )
{
# Delayed evaluation.
$entry = $self->parse_magic_line( @$entry ) if( scalar( @$entry ) == 3 );
next if( !defined( $entry ) );
my( $offtype, $offset, $numbytes, $type, $mask, $op, $testval, $template, $message, $subtests ) = @$entry;
$err->print( '>' x $depth );
if( $offtype == 1 )
{
lib/Apache2/SSI/File/Type.pm view on Meta::CPAN
{
if( $self->{error_returns_undef} )
{
return( $self->error( "Unable to open file '$file': $!" ) );
}
else
{
return( "x-system/x-error; $base_file: $!" );
}
};
$io->binmode;
# 3) Check for script
# if( ( -x( $file ) || ( $^O =~ /^(dos|mswin32|NetWare|symbian|win32)$/i && $file =~ /\.(?:pl|cgi)$/ ) ) &&
# if( ( -x( $file ) || $file =~ /\.(?:cgi|pl|t)$/ ) &&
# -T( _ ) )
my $default;
if( -x( $file ) && -T( _ ) )
{
# Note, some magic files include elaborate attempts to match #! header lines
# and return pretty responses but this slows down matching and is unnecessary.
lib/Apache2/SSI/URI.pm view on Meta::CPAN
# Returns /some/uri
my $parent = $uri->parent;
# The uri is now /some/uri/file.html/some/path
$uri->path_info( '/some/path' );
# The uri is now /some/uri/file.html/some/path?q=something&l=ja_JP
$uri->query_string( 'q=something&l=ja_JP' );
my $html = $uri->slurp_utf8;
my $raw = $uri->slurp({ binmode => ':raw' });
# Same as $uri->document_uri
my $uri = $uri->uri;
=head1 VERSION
v0.1.3
=head1 DESCRIPTION
lib/Apache2/SSI/URI.pm view on Meta::CPAN
Returns an object representation of the root uri, i.e. C</>
=head2 slurp
It returns the content of the L</filename>
it takes an hash reference of parameters:
=over 4
=item C<binmode>
my $content = $uri->slurp({ binmode => ':utf-8' });
=back
It will return undef and sets an L<Module::Generic/error> if there is no L</filename> value set or if the file cannot be opened.
=head2 slurp_utf8
It returns the content of the file L</filename> utf-8 decoded.
This is equivalent to:
my $content = $uri->slurp({ binmode => ':utf8' });
C<:utf8> is slightly a bit more lax than C<:utf-8>, so it you want strict utf8, you can do:
my $content = $uri->slurp({ binmode => ':utf-8' });
=head1 AUTHOR
Jacques Deguest E<lt>F<jack@deguest.jp>E<gt>
CPAN ID: jdeguest
L<https://gitlab.com/jackdeguest/Apache2-SSI>
=head1 SEE ALSO