Apache2-SSI

 view release on metacpan or  search on metacpan

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

        # try-catch
        $res = eval
        {
            Encode::encode( 'utf8', $res, Encode::FB_CROAK );
        };
        if( $@ )
        {
            $r->log->error( "${class} [PerlOutputFilterHandler]: encountered an error while trying to encode data into utf8: $@" );
            return( &Apache2::Const::DECLINED );
        }
        
        # $r->headers_out->unset( 'Content-Length' );
        my $len = length( $res );
        # try-catch
        eval
        {
            $r->headers_out->set( 'Content-Length' => $len );
            my $sent = $f->print( "$res" );
            $r->log->debug( "${class} [PerlOutputFilterHandler]: ${sent} bytes sent out." ) if( $debug > 0 );
        };
        if( $@ )
        {
            $r->log->error( "${class} encountered an error while sending resulting data via Apache2::Filter->print: $@" );
        }
        # This will cause a segfault
        # $r->rflush;
        return( &Apache2::Const::OK );
    }
}

sub init
{
    my $self = shift( @_ );
    my $class = ref( $self );
    my $args = {};
    if( scalar( @_ ) )
    {
        no warnings 'uninitialized';
        $args = Scalar::Util::reftype( $_[0] ) eq 'HASH'
            ? shift( @_ )
            : !( scalar( @_ ) % 2 )
                ? { @_ }
                : {};
    }
    my $uri = delete( $args->{document_uri} ) // '';
    $self->{html}           = '';
    $self->{apache_filter}  = '';
    $self->{apache_request} = '';
    $self->{document_root}  = '';
    # e.g.: [Value Undefined]
    $self->{echomsg}        = '';
    $self->{errmsg}         = '[an error occurred while processing this directive]';
    $self->{filename}       = '';
    $self->{legacy}         = 0;
    $self->{trunk}          = 0;
    $self->{remote_ip}      = '';
    $self->{sizefmt}        = 'abbrev';
    $self->{timefmt}        = undef;
    $self->{_init_strict_use_sub} = 1;
    $self->{_init_params_order} = [qw( apache_filter apache_request document_root document_uri )];
    $self->SUPER::init( %$args ) || return;
    $self->{_env}           = '';
    $self->{_path_info_processed} = 0;
    # Used to hold regular expression matches during eval in _eval_vars()
    # and make them available for the next evaluation
    $self->{_regexp_capture}= [];
    $self->{_uri_reset}     = 0;
    # A stack reflecting the current state of if/else parser.
    # Each entry is 1 when we've seen a true condition in this if-chain,
    # 0 when we haven't. Initially it's as if we're in a big true 
    # if-block with no else.
    $self->{if_state}       = [1];
    $self->{notes}          = '';
    $self->{suspend}        = [0];
    # undef means the current locale's default
    $self->mod_perl( defined( $MOD_PERL ) ? length( $MOD_PERL ) > 0 : 0 );
    my $r = $self->apache_request;
    if( $MOD_PERL && !$r )
    {
        # NOTE: Must check if GlobalRequest is set
        if( !( $r = $self->apache_request ) )
        {
            $r = Apache2::RequestUtil->request;
            if( $r )
            {
                $self->apache_request( $r );
                $self->apache_filter( $r->input_filters );
            }
            else
            {
                print( STDERR "${class} seems to be running under modperl version '$MOD_PERL', but could not get the Apache2::RequestRec object via Apache2::RequestUtil->request(). You need to enable GlobalRequest in your VirtualHost with: PerlOption...
            }
        }
    }
    my $p = {};
    if( length( "$uri" ) )
    {
        $p->{document_uri} = "$uri";
    }
    elsif( $r )
    {
        $p->{document_uri} = $r->unparsed_uri;
    }
    elsif( length( $self->env( 'DOCUMENT_URI' ) ) )
    {
        $p->{document_uri} = $self->env( 'DOCUMENT_URI' );
    }
    else
    {
        $p->{document_uri} = $self->env( 'REQUEST_URI' );
    }
    
    if( length( $self->{document_root} ) )
    {
        $p->{document_root} = $self->{document_root};
    }
    elsif( $r )
    {
        $p->{document_root} = $r->document_root;
    }
    else



( run in 0.349 second using v1.01-cache-2.11-cpan-ad19def0cd9 )