You are viewing a plain text version of this content. The canonical link for it is here.
Posted to embperl@perl.apache.org by Neil Gunton <ne...@nilspace.com> on 2001/02/17 19:57:26 UTC

EmbperlObject question

Hi Gerald,

I am starting to abstract out some code that will be common between
different websites on the same server, and I would like to make this
code into an object which can then be inherited by the individual
websites. I would like to know if you think the following method is a
good way to do it:

The document base is /www/mysite/com/htdocs. The following paths are
absolute to the file system root, not the website root:

/www/common/doc.html

	[!
		# Bunch of Perl methods
		sub execute
		{
			my ($self, $subs) = @_;
		}
	!]

	[$ sub foo $]
		[# Also some Embperl subs #]
	[$ endsub $]

/www/common/subs.html

	[!
		# Some common subs
	!]

/www/mysite/com/htdocs/base.html

	[- $subs = Execute ({object => 'subs.html'}) -]
	[- $object = Execute ({object => 'object.html'}) -]
	[- $object->execute ($subs) -]

/www/mysite/com/htdocs/subdir/object.html

	[! Execute ({isa => '/www/common/doc.html'}) !]

	[!
		# Redefine certain methods from doc.html	
		sub execute
		{
			my ($self, $subs) = @_;

			$self->SUPER::execute($subs);
		}
	!]

/www/mysite/com/htdocs/subdir/subs.html

	[! Execute ({isa => '/www/common/subs.html'}) !]

Does this architecture make sense? Also, is it ok to have Execute() call
a file which is outside the document base for the website? 

Sorry if these are dumb questions, it's just that I would like to make
sure I have this right before undertaking a major overhaul of my code
(yet again...) to make it more object oriented and reusable...

Thanks in advance,

-Neil

Re: EmbperlObject question

Posted by "G.Richter" <ri...@ecos.de>.
Hi Neil,

basicly this should work. There is no problem placing files outside the
document base for the website.

You may consider using the EMBPERL_OBJECT_ADDPATH to add /www/common/ to the
EmbperlObject serach path. Then you can include files from there by simply
saying

Execute ('doc.html')

moreover you are able to overwrite these files inside your document
hierachie and can include the original doc.html with a

[! Execute ({isa => '../doc.html'}) !]

and last but not least you may consider moving the Perl only part in a
normal Perl Library. In this case you are also be able to specify the class
you define inside this Perl module as a EMBPERL_OBJECT_HANDLER_CLASS. This
gives you the possibility to call methods from this package by simply saying

$r -> method ;

This are just some ideas that comes to my mind. You have to think about it,
how they fit into your site

Gerald


>
> The document base is /www/mysite/com/htdocs. The following paths are
> absolute to the file system root, not the website root:
>
> /www/common/doc.html
>
> [!
> # Bunch of Perl methods
> sub execute
> {
> my ($self, $subs) = @_;
> }
> !]
>
> [$ sub foo $]
> [# Also some Embperl subs #]
> [$ endsub $]
>
> /www/common/subs.html
>
> [!
> # Some common subs
> !]
>
> /www/mysite/com/htdocs/base.html
>
> [- $subs = Execute ({object => 'subs.html'}) -]
> [- $object = Execute ({object => 'object.html'}) -]
> [- $object->execute ($subs) -]
>
> /www/mysite/com/htdocs/subdir/object.html
>
> [! Execute ({isa => '/www/common/doc.html'}) !]
>
> [!
> # Redefine certain methods from doc.html
> sub execute
> {
> my ($self, $subs) = @_;
>
> $self->SUPER::execute($subs);
> }
> !]
>
> /www/mysite/com/htdocs/subdir/subs.html
>
> [! Execute ({isa => '/www/common/subs.html'}) !]
>
> Does this architecture make sense? Also, is it ok to have Execute() call
> a file which is outside the document base for the website?
>
> Sorry if these are dumb questions, it's just that I would like to make
> sure I have this right before undertaking a major overhaul of my code
> (yet again...) to make it more object oriented and reusable...
>
> Thanks in advance,
>
> -Neil
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
> For additional commands, e-mail: embperl-help@perl.apache.org
>
>