1Class::Adapter::Clear(3U)ser Contributed Perl DocumentatiColnass::Adapter::Clear(3)
2
3
4

NAME

6       Class::Adapter::Clear - A handy base Adapter class that makes no
7       changes
8

SYNOPSIS

10       Hello World with CGI.pm the normal way
11
12         # Load and create the CGI
13         use CGI;
14         $q = new CGI;
15
16         # Create the page
17         print $q->header,                    # HTTP Header
18               $q->start_html('hello world'), # Start the page
19               $q->h1('hello world'),         # Hello World!
20               $q->end_html;                  # End the page
21
22       Hello World with CGI.pm the Adapter'ed way
23
24         # Load and create the CGI
25         use CGI;
26         $q = new CGI;
27
28         # Convert to an Adapter
29         use Class::Adapter::Clear;
30         $q = new Class::Adapter::Clear( $q );
31
32         # Create the page
33         print $q->header,                    # HTTP Header
34               $q->start_html('hello world'), # Start the page
35               $q->h1('hello world'),         # Hello World!
36               $q->end_html;                  # End the page
37
38       Creating a CGI Adapter class using Class::Adapter::Clear
39
40         package My::CGI;
41
42         use base 'Class::Adapter::Clear';
43
44         # Optional - Create the thing we are decorating auto-magically
45         sub new {
46             my $class = shift;
47
48             # Create the object we are decorating
49             my $query = CGI->new(@_);
50
51             # Wrap it in the Adapter
52             $class->SUPER::new($query);
53         }
54
55         # Decorate the h1 method to change what is created
56         sub h1 {
57               my $self = shift;
58               my $str  = shift;
59
60           # Do something before the real method call
61           if ( defined $str and $str eq 'hello world' ) {
62               $str = 'Hello World!';
63           }
64
65           $self->_OBJECT_->($str, @_);
66         }
67

DESCRIPTION

69       "Class::Adapter::Clear" provides the base class for creating one common
70       type of Class::Adapter classes. For more power, move up to
71       Class::Adapter::Builder.
72
73       On it's own "Class::Adapter::Clear" passes all methods through to the
74       same method in the parent object with the same parameters, responds to
75       "->isa" like the parent object, and responds to "->can" like the parent
76       object.
77
78       It looks like a "Duck", and it quacks like a "Duck".
79
80       On this base, you simple implement whatever method you want to do
81       something special to.
82
83         # Different method, same parameters
84         sub method1 {
85             my $self = shift;
86             $self->_OBJECT_->method2(@_); # Call a different method
87         }
88
89         # Same method, different parameters
90         sub method1 {
91             my $self = shift;
92             $self->_OBJECT_->method1( lc($_[0]) ); # Lowercase the param
93         }
94
95         # Same method, same parameters, tweak the result
96         sub method1 {
97             my $self = shift;
98             my $rv = $self->_OBJECT_->method1(@_);
99             $rv =~ s/\n/<br>\n/g; # Add line-break HTML tags at each newline
100             return $rv;
101         }
102
103       As you can see, the advantage of this full-scale Adapter approach,
104       compared to inheritance, or function wrapping (see Class::Hook), is
105       that you have complete and utter freedom to do anything you might need
106       to do, without stressing the Perl inheritance model or doing anything
107       unusual or tricky with "CODE" references.
108
109       You may never need this much power. But when you need it, you really
110       need it.
111
112       As an aside, Class::Adapter::Clear is implemented with the following
113       Class::Adapter::Builder formula.
114
115         use Class::Adapter::Builder
116             ISA      => '_OBJECT_',
117             AUTOLOAD => 1;
118

METHODS

120   new $object
121       As does the base Class::Adapter class, the default "new" constructor
122       takes a single object as argument and creates a new object which holds
123       the passed object.
124
125       Returns a new "Class::Adapter::Clear" object, or "undef" if you do not
126       pass in an object.
127

SUPPORT

129       Bugs should be reported via the CPAN bug tracker at
130
131       http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Class-Adapter
132       <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Class-Adapter>
133
134       For other issues, contact the author.
135

AUTHOR

137       Adam Kennedy <adamk@cpan.org>
138

SEE ALSO

140       Class::Adapter, Class::Adapter::Builder
141
143       Copyright 2005 - 2010 Adam Kennedy.
144
145       This program is free software; you can redistribute it and/or modify it
146       under the same terms as Perl itself.
147
148       The full text of the license can be found in the LICENSE file included
149       with this module.
150
151
152
153perl v5.12.0                      2010-04-11          Class::Adapter::Clear(3)
Impressum