You are viewing a plain text version of this content. The canonical link for it is here.
Posted to embperl@perl.apache.org by Derrick Spell <de...@cdmplus.com> on 2005/05/24 21:21:26 UTC
Subroutine Inheritance
I want to set up a method accessed from the request object that will
allow me the option to create a page title based on the path to the
page. What I was thinking was:
/base.epl
[! sub title { print OUT "Company"; } !]
[- $req = shift -]
<title>[- $req->title() -]</title>
/title.epl
[! sub title { print OUT " "; } !]
/foo/title.epl
[! sub title {
my ($self) = @_;
$self->SUPER::title();
print OUT " : Products";
} !]
/foo/index.html
[! sub title {
my ($self) = @_;
$self->SUPER::title();
print OUT " : Widget";
} !]
Then, visiting /foo/index.html would give you a page with the title
"Company : Products : Widget". As I went deeper in the directory
tree, I could have more title.epl files, and thus a longer title.
For instance, if I add:
/foo/bar/title.epl
[! sub title {
my ($self) = @_;
$self->SUPER::title();
print OUT " : Downloads";
} !]
/foo/bar/index.html
[! sub title {
my ($self) = @_;
$self->SUPER::title();
print OUT " : Widget";
} !
Then the page /foo/bar/index.html would have the title "Company :
Products : Downloads : Widget". I can get the inheritance between
the /base.epl and whatever index.html page I have working fine.
That's no problem. The problem is getting the title.epl involved. I
want to use normal Embperl::Object file inheritance for title.epl
files, but want it to be inbetween the base.epl and index.html in the
heirarchy.
Is there a clever way to play with @ISA to accomplish this? Or
perhaps someone has a better idea for building titles?
-Derrick
Re: Subroutine Inheritance
Posted by Angus Lees <gu...@inodes.org>.
At Wed, 25 May 2005 10:16:55 -0400, Derrick Spell wrote:
> > In your page you say
> > [! Execute ({isa => 'title.epl'}) !]
> > In your title.epl you say
> > [! Execute ({isa => '../title.epl'}) !]
> > <title>[+ $req->title() +]</title>
Since you are setting the title per directory rather than per file
anyway (via "title.epl"), an alternative would be to simply use
Embperl::Object's inheritance directly, ie:
/title.epl:
Level 0 title
/base.epl:
...
<title>[- Execute('title.epl') -]</title>
...
/sub/dir/title.epl:
[- Execute('../title.epl') -]: A sub title
--
- Gus
---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org
Re: Subroutine Inheritance
Posted by Derrick Spell <de...@cdmplus.com>.
>> title "Base : Level 0". Is there anything I can do to make
>> the Execute isa in the base.epl actually include the
>> title.epl in the requested directory?
>>
>>
>
> Change the [! Execute({isa => 'title.epl'}); !] in base.epl to
>
> [- Execute({isa => 'title.epl'}); -]
>
> , because the search path is not set when [! !] is executed
>
> Gerald
>
Of course. I should have thought of that.
Thanks Gerald
---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org
RE: Subroutine Inheritance
Posted by Gerald Richter <ri...@ecos.de>.
> title "Base : Level 0". Is there anything I can do to make
> the Execute isa in the base.epl actually include the
> title.epl in the requested directory?
>
Change the [! Execute({isa => 'title.epl'}); !] in base.epl to
[- Execute({isa => 'title.epl'}); -]
, because the search path is not set when [! !] is executed
Gerald
---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org
Re: Subroutine Inheritance
Posted by Derrick Spell <de...@cdmplus.com>.
>> I want to set up a method accessed from the request object
>> that will allow me the option to create a page title based on
>> the path to the page. What I was thinking was:
>>
>
> In your page you say
>
> [! Execute ({isa => 'title.epl'}) !]
>
> In your title.epl you say
>
> [! Execute ({isa => '../title.epl'}) !]
>
> That should do the the trick of setting up @ISA
>
> BTW. I would use
>
> <title>[+ $req->title() +]</title>
>
> And then return the title string instead of print OUT
>
> Gerald
I was able to get this working with one minor modification. I had to
concatinate the call to $self->SUPER::title() with the title string
being returned by the function in order to see both. Otherwise, I
didn't see the text from the parent method. i.e., my index.html was:
[! Execute({isa => 'title.epl'}) !]
[! sub title {
my ($self) = @_;
$self->SUPER::title() . ' Page'
} !]
This works - but then I realized that if you don't override the title
() method on the individual pages, then you'll only get the title
from the base.epl. It won't print the recursive titles from
title.epl unless the requested page begins that recursion. So I
thought I would reverse my logic a little. What if the base.epl
started the recursion on title.epl. Then if my designers forget to
add the title() override to their pages (which is highly likely) they
will still get all titles up to that folder. Here is what I tried:
/base.epl
[! Execute({isa => 'title.epl'}); !]
[! sub title {
my ($self) = @_;
'Base' . $self->SUPER::title()
}; !]
/title.epl
[! sub title { ' : Level 0' }; !]
/foo/title.epl
[! Execute({isa => '../title.epl'}); !]
[! sub title {
my ($self) = @_;
$self->SUPER::title() . '' : Level 1'
}; !]
/foo/index.html
[# Nothing Here! #]
Here, hitting /title.epl stops the recursion rather than /base.epl
like in my first example. The only problem is that apparently the
Execute isa in the base.epl does not have the Embperl::Object
behavior of looking in the directory of the requested file. It seems
to literally be including only the /title.epl because when I request /
foo/index.html I get the title "Base : Level 0". Is there anything I
can do to make the Execute isa in the base.epl actually include the
title.epl in the requested directory?
-Derrick
---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org
RE: Subroutine Inheritance
Posted by Gerald Richter <ri...@ecos.de>.
>
> I want to set up a method accessed from the request object
> that will allow me the option to create a page title based on
> the path to the page. What I was thinking was:
>
In your page you say
[! Execute ({isa => 'title.epl'}) !]
In your title.epl you say
[! Execute ({isa => '../title.epl'}) !]
That should do the the trick of setting up @ISA
BTW. I would use
<title>[+ $req->title() +]</title>
And then return the title string instead of print OUT
Gerald
> /base.epl
> [! sub title { print OUT "Company"; } !]
> [- $req = shift -]
> <title>[- $req->title() -]</title>
>
> /title.epl
> [! sub title { print OUT " "; } !]
>
> /foo/title.epl
> [! sub title {
> my ($self) = @_;
> $self->SUPER::title();
> print OUT " : Products";
> } !]
>
> /foo/index.html
> [! sub title {
> my ($self) = @_;
> $self->SUPER::title();
> print OUT " : Widget";
> } !]
>
> Then, visiting /foo/index.html would give you a page with the
> title "Company : Products : Widget". As I went deeper in the
> directory tree, I could have more title.epl files, and thus a
> longer title. For instance, if I add:
>
> /foo/bar/title.epl
> [! sub title {
> my ($self) = @_;
> $self->SUPER::title();
> print OUT " : Downloads";
> } !]
>
> /foo/bar/index.html
> [! sub title {
> my ($self) = @_;
> $self->SUPER::title();
> print OUT " : Widget";
> } !
>
> Then the page /foo/bar/index.html would have the title
> "Company : Products : Downloads : Widget". I can get the
> inheritance between the /base.epl and whatever index.html
> page I have working fine. That's no problem. The problem is
> getting the title.epl involved. I want to use normal
> Embperl::Object file inheritance for title.epl files, but
> want it to be inbetween the base.epl and index.html in the heirarchy.
>
> Is there a clever way to play with @ISA to accomplish this?
> Or perhaps someone has a better idea for building titles?
>
>
> -Derrick
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org