.\" 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 "Class::Adapter::Clear 3pm" .TH Class::Adapter::Clear 3pm "2022-12-04" "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" Class::Adapter::Clear \- A handy base Adapter class that makes no changes .SH "VERSION" .IX Header "VERSION" version 1.09 .SH "SYNOPSIS" .IX Header "SYNOPSIS" \&\fBHello World with \s-1CGI\s0.pm the normal way\fR .PP .Vb 3 \& # Load and create the CGI \& use CGI; \& $q = new CGI; \& \& # Create the page \& print $q\->header, # HTTP Header \& $q\->start_html(\*(Aqhello world\*(Aq), # Start the page \& $q\->h1(\*(Aqhello world\*(Aq), # Hello World! \& $q\->end_html; # End the page .Ve .PP \&\fBHello World with \s-1CGI\s0.pm the Adapter'ed way\fR .PP .Vb 3 \& # Load and create the CGI \& use CGI; \& $q = new CGI; \& \& # Convert to an Adapter \& use Class::Adapter::Clear; \& $q = new Class::Adapter::Clear( $q ); \& \& # Create the page \& print $q\->header, # HTTP Header \& $q\->start_html(\*(Aqhello world\*(Aq), # Start the page \& $q\->h1(\*(Aqhello world\*(Aq), # Hello World! \& $q\->end_html; # End the page .Ve .PP \&\fBCreating a \s-1CGI\s0 Adapter class using Class::Adapter::Clear\fR .PP .Vb 1 \& package My::CGI; \& \& use base \*(AqClass::Adapter::Clear\*(Aq; \& \& # Optional \- Create the thing we are decorating auto\-magically \& sub new { \& my $class = shift; \& \& # Create the object we are decorating \& my $query = CGI\->new(@_); \& \& # Wrap it in the Adapter \& $class\->SUPER::new($query); \& } \& \& # Decorate the h1 method to change what is created \& sub h1 { \& my $self = shift; \& my $str = shift; \& \& # Do something before the real method call \& if ( defined $str and $str eq \*(Aqhello world\*(Aq ) { \& $str = \*(AqHello World!\*(Aq; \& } \& \& $self\->_OBJECT_\->($str, @_); \& } .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" \&\f(CW\*(C`Class::Adapter::Clear\*(C'\fR provides the base class for creating one common type of Class::Adapter classes. For more power, move up to Class::Adapter::Builder. .PP On it's own \f(CW\*(C`Class::Adapter::Clear\*(C'\fR passes all methods through to the same method in the parent object with the same parameters, responds to \&\f(CW\*(C`\->isa\*(C'\fR like the parent object, and responds to \f(CW\*(C`\->can\*(C'\fR like the parent object. .PP It looks like a \f(CW\*(C`Duck\*(C'\fR, and it quacks like a \f(CW\*(C`Duck\*(C'\fR. .PP On this base, you simple implement whatever method you want to do something special to. .PP .Vb 5 \& # Different method, same parameters \& sub method1 { \& my $self = shift; \& $self\->_OBJECT_\->method2(@_); # Call a different method \& } \& \& # Same method, different parameters \& sub method1 { \& my $self = shift; \& $self\->_OBJECT_\->method1( lc($_[0]) ); # Lowercase the param \& } \& \& # Same method, same parameters, tweak the result \& sub method1 { \& my $self = shift; \& my $rv = $self\->_OBJECT_\->method1(@_); \& $rv =~ s/\en/
\en/g; # Add line\-break HTML tags at each newline \& return $rv; \& } .Ve .PP As you can see, the advantage of this full-scale \fIAdapter\fR approach, compared to inheritance, or function wrapping (see Class::Hook), is that you have complete and utter freedom to do anything you might need to do, without stressing the Perl inheritance model or doing anything unusual or tricky with \f(CW\*(C`CODE\*(C'\fR references. .PP You may never need this much power. But when you need it, you \fBreally\fR need it. .PP As an aside, Class::Adapter::Clear is implemented with the following Class::Adapter::Builder formula. .PP .Vb 3 \& use Class::Adapter::Builder \& ISA => \*(Aq_OBJECT_\*(Aq, \& AUTOLOAD => 1; .Ve .SH "METHODS" .IX Header "METHODS" .ie n .SS "new $object" .el .SS "new \f(CW$object\fP" .IX Subsection "new $object" As does the base Class::Adapter class, the default \f(CW\*(C`new\*(C'\fR constructor takes a single object as argument and creates a new object which holds the passed object. .PP Returns a new \f(CW\*(C`Class::Adapter::Clear\*(C'\fR object, or \f(CW\*(C`undef\*(C'\fR if you do not pass in an object. .SH "SEE ALSO" .IX Header "SEE ALSO" Class::Adapter, Class::Adapter::Builder .SH "SUPPORT" .IX Header "SUPPORT" Bugs may be submitted through the \s-1RT\s0 bug tracker (or bug\-Class\-Adapter@rt.cpan.org ). .SH "AUTHOR" .IX Header "AUTHOR" Adam Kennedy .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" This software is copyright (c) 2005 by Adam Kennedy. .PP This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.