.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Object 3pm" .TH Object 3pm "2023-01-22" "perl v5.36.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Embperl::Object \- Extents Embperl for building whole website with reusable components and objects .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 8 \& \& EMBPERL_APPNAME unique\-name \& EMBPERL_OBJECT_BASE base.htm \& EMBPERL_URIMATCH "\e.htm.?|\e.epl$" \& SetHandler perl\-script \& PerlHandler Embperl::Object \& Options ExecCGI \& .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" \&\fIEmbperl::Object\fR allows you to build object-oriented (\s-1OO\s0) websites using \&\s-1HTML\s0 components which implement inheritance via subdirectories. This enables elegant architectures and encourages code reuse. The use of inheritance also enables a website-wide \*(L"look and feel\*(R" to be specified in a single \s-1HTML\s0 file, which is then used as a template for every other page on the site. This template can include other modules which can be overridden in subdirectories; even the template itself can be overridden. In a nutshell, \fIEmbperl::Object\fR makes the design of large websites much more intuitive, allowing object-oriented concepts to be utilised to the fullest while staying within the \*(L"rapid application development\*(R" model of Perl and \s-1HTML.\s0 .PP \&\fIEmbperl::Object\fR is basically a \fImod_perl\fR handler or could be invoked offline and helps you to build a whole page out of smaller parts. Basically it does the following: .PP When a request comes in, a page, which name is specified by \s-1EMBPERL_OBJECT_BASE\s0, is searched in the same directory as the requested page. If the pages isn't found, \&\fIEmbperl::Object\fR walking up the directory tree until it finds the page, or it reaches \f(CW\*(C`DocumentRoot\*(C'\fR or the directory specified by \s-1EMBPERL_OBJECT_STOPDIR\s0. .PP This page is then called as frame for building the real page. Addtionaly \fIEmbperl::Object\fR sets the search path to contain all directories it had to walk before finding that page. If \s-1EMBPERL_OBJECT_STOPDIR\s0 is set the path contains all directories up to the in \s-1EMBPERL_OBJECT_STOPDIR\s0 specified one. .PP This frame page can now include other pages, using the \f(CW\*(C`Embperl::Execute\*(C'\fR method. Because the search path is set by \fIEmbperl::Object\fR the included files are searched in the directories starting at the directory of the original request walking up thru the directory which contains the base page. This means that you can have common files, like header, footer etc. in the base directory and override them as necessary in the subdirectory. .PP To include the original requested file, you need to call \f(CW\*(C`Execute\*(C'\fR with a \f(CW\*(Aq*\*(Aq\fR as filename. To call the the same file, but in an upper directory you can use the special shortcut \f(CW\*(C`../*\*(C'\fR. .PP Additionally \fIEmbperl::Object\fR sets up a inherence hierachie for you: The requested page inherit from the base page and the base page inherit from a class which could be specified by \f(CW\*(C`EMBPERL_OBJECT_HANDLER_CLASS\*(C'\fR, or if \f(CW\*(C`EMBPERL_OBJECT_HANDLER_CLASS\*(C'\fR is not set, from \f(CW\*(C`Embperl::Req\*(C'\fR. That allows you to define methods in base page and overwrite them as necessary in the original requested files. For this purpose a request object, which is blessed into the package of the requested page, is given as first parameter to each page (in \f(CW$_[0]\fR). Because this request object is a hashref, you can also use it to store additional data, which should be available in all components. \&\fIEmbperl\fR does not use this hash itself, so you are free to store whatever you want. Methods can be ordinary Perl sub's (defined with [! sub foo { ... } !] ) or Embperl sub's (defined with [$sub foo $] .... [$endsub $]) . .SH "Runtime configuration" .IX Header "Runtime configuration" The runtime configuration is done by setting environment variables, in your web server's configuration file. Basically the configuration is the same as for normal Embperl. All Embperl configuration directives also applies to Embperl::Object. There are a few additional configuration directives listed below. Addtionaly you have to set the \f(CW\*(C`PerlHandler\*(C'\fR to \&\f(CW\*(C`Embperl::Object\*(C'\fR when running under mod_perl or use \f(CW\*(C`epocgi.pl\*(C'\fR instead of \f(CW\*(C`embpcgi.pl\*(C'\fR when running as \s-1CGI\s0 Script. .SS "\s-1EMBPERL_DECLINE\s0" .IX Subsection "EMBPERL_DECLINE" Perl regex which files should be ignored by \fIEmbperl::Object\fR .SS "\s-1EMBPERL_FILESMATCH\s0" .IX Subsection "EMBPERL_FILESMATCH" Perl regex which files should be processed by \fIEmbperl::Object\fR .SS "\s-1EMBPERL_OBJECT_BASE\s0" .IX Subsection "EMBPERL_OBJECT_BASE" Name of the base page to search for .SS "\s-1EMBPERL_OBJECT_STOPDIR\s0" .IX Subsection "EMBPERL_OBJECT_STOPDIR" Directory where to stop searching for the base page .SS "\s-1EMBPERL_OBJECT_ADDPATH\s0" .IX Subsection "EMBPERL_OBJECT_ADDPATH" Additional directories where to search for pages. Directories are separated by \f(CW\*(C`;\*(C'\fR (on Unix \f(CW\*(C`:\*(C'\fR works also). This path is \&\fBalways\fR appended to the searchpath. .SS "\s-1EMBPERL_OBJECT_FALLBACK\s0" .IX Subsection "EMBPERL_OBJECT_FALLBACK" If the requested file is not found the file given by \f(CW\*(C`EMBPERL_OBJECT_FALLBACK\*(C'\fR is displayed instead. If \f(CW\*(C`EMBPERL_OBJECT_FALLBACK\*(C'\fR isn't set a staus 404, \s-1NOT_FOUND\s0 is returned as usual. If the fileame given in \&\f(CW\*(C`EMBPERL_OBJECT_FALLBACK\*(C'\fR doesn't contain a path, it is searched thru the same directories as \f(CW\*(C`EMBPERL_OBJECT_BASE\*(C'\fR. .SS "\s-1EMBPERL_OBJECT_HANDLER_CLASS\s0" .IX Subsection "EMBPERL_OBJECT_HANDLER_CLASS" If you specify this call the template base and the requested page inherit all methods from this class. This class must contain \f(CW\*(C`Embperl::Req\*(C'\fR in his \&\f(CW@ISA\fR array. .SS "\s-1EMBPERL_OBJECT_APP\s0" .IX Subsection "EMBPERL_OBJECT_APP" Filename of the application object. The file should contain the Perl code for the application object. The must be no package name given (as the package is set by Embperl::Object), but the \f(CW@ISA\fR should point to Embperl::App. If set this file is searched through the same search path as any content file. After a successful load the init method is called with the Embperl request object as parameter. The init method can change the parameters inside the request object to influence the current request. .PP The init method should return zero or a valid \s-1HTTP\s0 status code (e.g. return 302 and set the location header in \f(CW%http_headers_out\fR) .SH "Execute" .IX Header "Execute" You can use \fIEmbperl::Object\fR also offline. You can do this by calling the function \&\f(CW\*(C`Embperl::Object::Execute\*(C'\fR. \f(CW\*(C`Execute\*(C'\fR takes a hashref as argument, which can contains the same parameters as the \f(CW\*(C`Embperl::Execute\*(C'\fR function. Additionally you may specify the following parameters: .IP "object_base" 4 .IX Item "object_base" same as \f(CW$ENV\fR{\s-1EMBPERL_OBJECT_BASE\s0} .IP "object_addpath" 4 .IX Item "object_addpath" same as \f(CW$ENV\fR{\s-1EMBPERL_OBJECT_ADDPATH\s0} .IP "object_stopdir" 4 .IX Item "object_stopdir" same as \f(CW$ENV\fR{\s-1EMBPERL_OBJECT_STOPDIR\s0} .IP "object_fallback" 4 .IX Item "object_fallback" same as \f(CW$ENV\fR{\s-1EMBPERL_OBJECT_FALLBACK\s0} .IP "object_handler_class" 4 .IX Item "object_handler_class" same as \f(CW$ENV\fR{\s-1EMBPERL_OBJECT_HANDLER_CLASS\s0} .PP See also the \f(CW\*(C`object\*(C'\fR and \f(CW\*(C`isa\*(C'\fR parameters in Embperl's Execute function, on how to setup additional inherence and how to create Perl objects out of Embperl pages. .SH "Basic Example" .IX Header "Basic Example" With the following setup: .PP .Vb 7 \& \& PerlSetEnv EMBPERL_OBJECT_BASE base.htm \& PerlSetEnv EMBPERL_FILESMATCH "\e.htm.?|\e.epl$" \& SetHandler perl\-script \& PerlHandler Embperl::Object \& Options ExecCGI \& .Ve .PP \&\fBDirectory Layout:\fR .PP .Vb 6 \& /foo/base.htm \& /foo/head.htm \& /foo/foot.htm \& /foo/page1.htm \& /foo/sub/head.htm \& /foo/sub/page2.htm .Ve .PP \&\fB/foo/base.htm:\fR .PP .Vb 10 \& \& \& Example \& \& \& [\- Execute (\*(Aqhead.htm\*(Aq) \-] \& [\- Execute (\*(Aq*\*(Aq) \-] \& [\- Execute (\*(Aqfoot.htm\*(Aq) \-] \& \& .Ve .PP \&\fB/foo/head.htm:\fR .PP .Vb 1 \&

head from foo

.Ve .PP \&\fB/foo/sub/head.htm:\fR .PP .Vb 1 \&

another head from sub

.Ve .PP \&\fB/foo/foot.htm:\fR .PP .Vb 1 \&
Footer
.Ve .PP \&\fB/foo/page1.htm:\fR .PP .Vb 1 \& PAGE 1 .Ve .PP \&\fB/foo/sub/page2.htm:\fR .PP .Vb 1 \& PAGE 2 .Ve .PP \&\fB/foo/sub/index.htm:\fR .PP .Vb 1 \& Index of /foo/sub .Ve .PP If you now request \fBhttp://host/foo/page1.htm\fR you will get the following page .PP .Vb 10 \& \& \& Example \& \& \&

head from foo

\& PAGE 1 \&
Footer
\& \& .Ve .PP If you now request \fBhttp://host/foo/sub/page2.htm\fR you will get the following page .PP .Vb 10 \& \& \& Example \& \& \&

another head from sub

\& PAGE 2 \&
Footer
\& \& .Ve .PP If you now request \fBhttp://host/foo/sub/\fR you will get the following page .PP .Vb 10 \& \& \& Example \& \& \&

another head from sub

\& Index of /foo/sub \&
Footer
\& \& .Ve .SH "Example for using method calls" .IX Header "Example for using method calls" (Everything not given here is the same as in the example above) .PP \&\fB/foo/base.htm:\fR .PP .Vb 1 \& [! \& \& sub new \& { \& my $self = shift ; \& \& # here we attach some data to the request object \& $self \-> {fontsize} = 3 ; \& } \& \& # Here we give a default title \& sub title { \*(AqTitle not given\*(Aq } ; \& \& !] \& \& [\- \& \& # get the request object of the current request \& $req = shift ; \& \& # here we call the method new \& $req \-> new ; \& \& \-] \& \& \& \& [+ $req \-> title +] \& \& \& [\- Execute (\*(Aqhead.htm\*(Aq) \-] \& [\- Execute (\*(Aq*\*(Aq) \-] \& [\- Execute (\*(Aqfoot.htm\*(Aq) \-] \& \& .Ve .PP \&\fB/foo/head.htm:\fR .PP .Vb 7 \& [# \& here we use the fontsize \& Note that \& $foo = $_[0] \& is the same as writing \& $foo = shift \& #] \& \& {fontsize} +]>header .Ve .PP \&\fB/foo/sub/page2.htm:\fR .PP .Vb 1 \& [! \& \& sub new \& { \& my $self = shift ; \& \& # here we overwrite the new method form base.htm \& $self \-> {fontsize} = 5 ; \& } \& \& # Here we overwrite the default title \& sub title { \*(AqTitle form page 2\*(Aq } ; \& \& !] \& \& PAGE 2 .Ve .SH "Author" .IX Header "Author" G. Richter (richter at embperl dot org) .SH "See Also" .IX Header "See Also" \&\fBperl\fR\|(1), Embperl, mod_perl, Apache httpd