Discussion:
[cgi-prototype-users] Package name output
LD
2005-05-03 01:45:34 UTC
Permalink
Hi there,

If I have the following as part of a template definition (in a file):
[% self.CGI.h1(self.reflect.package) %]

...it returns the proper name as expected. If I however do:
sub someTemplate { \ <<'EOT'; }
[% self.CGI.header %]
[% self.CGI.h1(self.reflect.package) %]
EOT

...I instead get something like: PKG0x958d0c

How might this be fixed?

Cheers.

--
LD
Terrence Brannon
2005-05-03 06:31:37 UTC
Permalink
Post by LD
Hi there,
Hi LD,
Post by LD
[% self.CGI.h1(self.reflect.package) %]
<h1>[% self.reflect.package %]</h1>

looks cleaner to my personal taste.
Post by LD
sub someTemplate { \ <<'EOT'; }
[% self.CGI.header %]
[% self.CGI.h1(self.reflect.package) %]
EOT
I don't have an answer to your question, but would like to make a
comment.

One of my initial criticisms of the CGI::Prototype docs was what you
are doing here. The call to $self->CGI->header is more general and
will apply to many more pages/objects than the current page. It does
not belong in the same method as a page-local call such as
$self->reflect->package: it is application-wide not page-local.

I think it belongs in render_enter in a base class... then, if a
particular page needs to send a certain content type, it can override
the method.
--
Carter's Compass: I know I'm on the right track when,
by deleting something, I'm adding functionality.
Randal L. Schwartz
2005-05-03 11:28:09 UTC
Permalink
LD> Hi there,
LD> If I have the following as part of a template definition (in a file):
LD> [% self.CGI.h1(self.reflect.package) %]

LD> ...it returns the proper name as expected. If I however do:
LD> sub someTemplate { \ <<'EOT'; }
LD> [% self.CGI.header %]
LD> [% self.CGI.h1(self.reflect.package) %]
LD> EOT

LD> ...I instead get something like: PKG0x958d0c

Well, that's probably the actual package name of that lightweight
class.

Here's what I did for a client recently. In App.pm, I added

sub title {
my $self = shift;

local $_ = $self->shortname;
tr/_/ /;
s/\b([a-z])/\U$1/g;
return "Initech Corporation Conference Registration: $_";
}

And in my WRAPPER.tt, I have:

[% self.CGI.start_html("-title", self.title) %]

This defines the default titlebar related to the state name.
And yet, any specific state can provide

sub title { "Acquiring Remote Latinum" }

to override that.

"This (and other) tips will be found in the forthcoming
CGI::Prototype::Cookbook, coming soon to a CPAN near you. Offer void
where prohibited."

;-)
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<***@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
LD
2005-05-03 13:48:13 UTC
Permalink
Hi there,
Post by Randal L. Schwartz
LD> sub someTemplate { \ <<'EOT'; }
LD> [% self.CGI.header %]
LD> [% self.CGI.h1(self.reflect.package) %]
LD> EOT
LD> ...I <..> get something like: PKG0x958d0c
Well, that's probably the actual package name of that lightweight
class.
Possibly - but its real name (e.g., "Main") is properly spat out when
such a definition is within a template file; but not with the above.
Perhaps it needs detainting to work...
Post by Randal L. Schwartz
local $_ = $self->shortname;
tr/_/ /;
tr/::/ /;
Post by Randal L. Schwartz
s/\b([a-z])/\U$1/g;
Ahh, yep - that works. Cheers.
Post by Randal L. Schwartz
"This (and other) tips will be found in the forthcoming
CGI::Prototype::Cookbook, coming soon to a CPAN near you. Offer void
where prohibited."
No doubt it'll be a useful resource...

with regards,
--

LD
Randal L. Schwartz
2005-05-03 14:16:14 UTC
Permalink
LD> Possibly - but its real name (e.g., "Main") is properly spat out when
LD> such a definition is within a template file; but not with the
LD> above. Perhaps it needs detainting to work...

Loading...