Hi gdo

Are you using HTML:Mason rather than Mason 2? (and if so, why? ;)

http://search.cpan.org/~drolsky/HTML-Mason-1.56/lib/HTML/Mason.pm#WAIT_-_HAVE_YOU_SEEN_MASON_2
?



I've attached 2 files that essentially show what I kludged up back in 2004
or 5. Or whenever.

The ApacheHandler is massively cut down, but hopefully it gives the rough
idea.


My apache config contains something along the lines of:

PerlModule Apache2::compat
PerlSetVar MasonArgsMethod mod_perl
PerlOptions +GlobalRequest
PerlModule EDT::Mason::ApacheHandler

<Location />
Require all granted
SetHandler modperl
PerlHandler EDT::Mason::ApacheHandler
</Location>


Works for me - YMMV  (there are still several sites still running on it
having been migrated from box to box - I can confirm against Apache 2.4.6 ;)


Sorry to not have a clean and concise answer...


Alex




On 16 April 2017 at 20:16, Guido Brugnara <g...@leader.it> wrote:

> To set up the MasonX::Request::ExtendedCompRoot component I have add
> these two rows in my Apache 2.4 config file:
>
>    PerlSetVar  MasonRequestClass   MasonX::Request::ExtendedCompRoot
>    PerlSetVar  MasonResolverClass  MasonX::Resolver::ExtendedCompRoot
>
> ... but the Apache 2.4 (or 2.2) server respond with this error:
>
>    [Sun Apr 16 20:26:17.446351 2017] [perl:error] [pid 5672] [client
> 192.168.9.2:40230] Undefined subroutine &HTML::Mason::Resolver::File::
> ApacheHandler::apache_request_to_comp_path called at /
>
> Someone use with success this component with Apache 2?
>
> My goal is to call to a specific component root, for example to partially
> change the component beavior in main root with a component in the secondary
> root which then calls the main component.
>
> There are MasonX::Request::ExtendedCompRoot alternatives?
>
> Any suggestions would be appreciated.
>
> bye
> gdo
>
> ------------------------------------------------------------
> ------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> _______________________________________________
> Mason-users mailing list
> Mason-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/mason-users
>
package EDT::Mason::Request;

use Carp;

our $AUTOLOAD;


eval { require Apache; };
eval { require Apache::Request; };
eval { require Apache2::Request};
eval { require Apache2::RequestUtil; };
eval { require Apache2::Upload; };


sub new
	{
	my $class = shift;
	my $self = {};
	my $r = shift;
	unless ($r)
		{
		if($ENV{MOD_PERL})
			{
			$r = $ENV{MOD_PERL_API_VERSION} >= 2 ? Apache2::RequestUtil->request : Apache::Request->request;
			}
		}
	$self->{request} = $r;
	my $req_ref = ref $r;
	$self->{request_type} = 'apache' if $req_ref =~ m/Apache/i;
	$self->{request_type} = 'apache2' if $req_ref =~ m/Apache2/i;
	

	my %args = ();
	my $argsin = $r->args;
	my @argschunks = split('&', $argsin);
	foreach my $chunk(@argschunks)
		{
		my ($key, $value) = split('=', $chunk);
		if (defined($args{$key}))
			{
			unless (ref $args{$key})
				{
				$args{$key} = [$args{$key}];
				}
			push(@{$args{$key}}, $value);
			}
		else
			{
			$args{$key} = $value;
			}
		}
	$self->{args} = \%args;
	my %vars = %args;
	$self->{vars} = \%vars;

	bless($self);
	return $self;
	}

sub version
	{
	my $self = shift;
	return $self->{request_type};
	}

sub var
	{
	my $self = shift;
	my $var = shift;
	my $value = shift;
	if (defined($value))
		{
		$self->{vars}->{$var} = $value;
		return;
		}
	return $self->{vars}->{$var};
	}
	
sub delete_var
	{
	my $self = shift;
	my $var = shift;
	delete $self->{vars}->{$var};
	}
	
sub vars
	{
	my $self = shift;
	
	if (wantarray)
		{
		return %{$self->{vars}};
		}
	return $self->{vars};
	}

sub uri
	{
	my $self = shift;
	return $self->{request}->uri(@_);
	}

sub unparsed_uri
	{
	my $self = shift;
	#if ($self->{request_type} eq 'apache2')
	#	{
	#	return $self->{request}->unparsed_uri;
	#	}
	#else
	#	{
		my $args = $self->args_as_string;
		return $args ? $self->uri.'?'.$args : $self->uri;
	#	}
	}

sub args
	{
	my $self = shift;
	
	if (wantarray)
		{
		return %{$self->{args}};
		}
	else
		{
		unless ($self->{args_as_string})
			{
			my %args = %{$self->{args}};
			my $argstring = '';
			foreach my $arg (sort keys %args)
				{
				if (ref $args{$arg})
					{
					foreach (@{$args{$arg}})
						{
						$argstring .= '&' if $argstring;
						$argstring .= "$arg=$_";
						}
					}
				else
					{
					$argstring .= '&' if $argstring;
					$argstring .= "$arg=$args{$arg}";
					}
				}
			$self->{args_as_string} = $argstring;
			}
		return $self->{args_as_string};
		}
	}

sub args_as_string
	{
	my $self = shift;
	my $string = $self->args;
	return $string;
	}

sub documentroot
	{
	my $self = shift;
	return $self->{request}->document_root(@_);
	}

sub servername
	{
	my $self = shift;
	return $self->{request}->server->server_hostname;
	}

sub remoteip
	{
	my $self = shift;
	return $self->{request}->get_remote_host;
	}

sub referrer
	{
	my $self = shift;
	return $self->{request}->header_in('referer');
	}

sub https
	{
	my $self = shift;
	# this replaces $ENV{HTTPS}
	# as can be seen, it doesn't yet really
	return;
	}

sub upload
	{
	my $self = shift;
	if ($self->{request_type} eq 'apache2')
		{
		my $req = Apache2::Request->new($self->{request});
		eval { require Apache2::Upload; };
		return $req->upload(@_);
		}
	else
		{
		#my $req = Apache::Request->new($self->{request});
		# hmmm. for some reason $self->{request} gets stored as Apache::SCALAR rather than Apache::Request::SCALAR
		# this causes it to not know about upload
		my $req = $HTML::Mason::Commands::r;
		return $req->upload(@_);
		}
	}

sub AUTOLOAD
	{
	my $self = shift;
	my $type = ref($self) or croak "$self is not an object";
	my $field = $AUTOLOAD;
	$field =~ s/.*://;   # strip fully-qualified portion
	return if $field eq 'DESTROY';
	if ($self->{request}->can($field))
		{
		return $self->{request}->$field(@_);
		}
	return $self->var($field, $_);
	}


sub cache_request
	{
	my $REQUEST = shift;
	my @cachevals = $REQUEST->_cache_request_value(@_);
	$REQUEST->header_out($cachevals[0],  $cachevals[1]);
	}
sub _cache_request_value
	{
	my ($REQUEST, $cachestamp) = @_;
	$cachestamp ||= 365*24*60*60;
	my $http = $REQUEST->_http_version;
	if ($http eq '1.1')
		{
		return ('Cache-Control', "max-age=" . $cachestamp);
		}
	else
		{
		return ('Expires', HTTP::Date::time2str(time + $cachestamp));
		}
	}
sub _http_version
	{
	my $REQUEST = shift;
	my $version = ($REQUEST->protocol =~ /(\d\.\d)/ && $1 >= 1.1) ? '1.1' : '1.0';
	return $version;
	}



return 1;
#!/usr/bin/perl
#
## EDT Mason Handler
## Apache 1.3 and 2 version

package EDT::Mason::ApacheHandler;

use strict;
use HTML::Mason::ApacheHandler;

## load up some common modules
{
  package HTML::Mason::Commands;
  use EDT::Mason::Request;
}

## the apache handler instance
our $ah;

## initialize apache handler
sub init
  {
  my %args = (
		args_method => 'mod_perl',
		data_dir => '$data_dir',
		request_class => 'MasonX::Request::ExtendedCompRoot',
		resolver_class => 'MasonX::Resolver::ExtendedCompRoot',
		comp_root => ['$comp_root']
  );
  $ah = HTML::Mason::ApacheHandler->new(%args);
  }

## process request
sub handler
	{
	my $r = shift;
	my $REQUEST = EDT::Mason::Request->new($r);
  # ...
	$HTML::Mason::Commands::REQUEST = $REQUEST;
  #...
	return $ah->handle_request($r);
	}

# return true
1;
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Mason-users mailing list
Mason-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mason-users

Reply via email to