File Coverage

blib/lib/Class/Adapter/Clear.pm
Criterion Covered Total %
statement 8 8 100.0
branch n/a
condition n/a
subroutine 3 3 100.0
pod n/a
total 11 11 100.0


line stmt bran cond sub pod time code
1             package Class::Adapter::Clear;
2             # ABSTRACT: A handy base Adapter class that makes no changes
3              
4             #pod =pod
5             #pod
6             #pod =head1 SYNOPSIS
7             #pod
8             #pod B
9             #pod
10             #pod # Load and create the CGI
11             #pod use CGI;
12             #pod $q = new CGI;
13             #pod
14             #pod # Create the page
15             #pod print $q->header, # HTTP Header
16             #pod $q->start_html('hello world'), # Start the page
17             #pod $q->h1('hello world'), # Hello World!
18             #pod $q->end_html; # End the page
19             #pod
20             #pod B
21             #pod
22             #pod # Load and create the CGI
23             #pod use CGI;
24             #pod $q = new CGI;
25             #pod
26             #pod # Convert to an Adapter
27             #pod use Class::Adapter::Clear;
28             #pod $q = new Class::Adapter::Clear( $q );
29             #pod
30             #pod # Create the page
31             #pod print $q->header, # HTTP Header
32             #pod $q->start_html('hello world'), # Start the page
33             #pod $q->h1('hello world'), # Hello World!
34             #pod $q->end_html; # End the page
35             #pod
36             #pod B
37             #pod
38             #pod package My::CGI;
39             #pod
40             #pod use base 'Class::Adapter::Clear';
41             #pod
42             #pod # Optional - Create the thing we are decorating auto-magically
43             #pod sub new {
44             #pod my $class = shift;
45             #pod
46             #pod # Create the object we are decorating
47             #pod my $query = CGI->new(@_);
48             #pod
49             #pod # Wrap it in the Adapter
50             #pod $class->SUPER::new($query);
51             #pod }
52             #pod
53             #pod # Decorate the h1 method to change what is created
54             #pod sub h1 {
55             #pod my $self = shift;
56             #pod my $str = shift;
57             #pod
58             #pod # Do something before the real method call
59             #pod if ( defined $str and $str eq 'hello world' ) {
60             #pod $str = 'Hello World!';
61             #pod }
62             #pod
63             #pod $self->_OBJECT_->($str, @_);
64             #pod }
65             #pod
66             #pod =head1 DESCRIPTION
67             #pod
68             #pod C provides the base class for creating one common
69             #pod type of L classes. For more power, move up to
70             #pod L.
71             #pod
72             #pod On it's own C passes all methods through to the same
73             #pod method in the parent object with the same parameters, responds to
74             #pod C<-Eisa> like the parent object, and responds to C<-Ecan> like
75             #pod the parent object.
76             #pod
77             #pod It looks like a C, and it quacks like a C.
78             #pod
79             #pod On this base, you simple implement whatever method you want to do
80             #pod something special to.
81             #pod
82             #pod # Different method, same parameters
83             #pod sub method1 {
84             #pod my $self = shift;
85             #pod $self->_OBJECT_->method2(@_); # Call a different method
86             #pod }
87             #pod
88             #pod # Same method, different parameters
89             #pod sub method1 {
90             #pod my $self = shift;
91             #pod $self->_OBJECT_->method1( lc($_[0]) ); # Lowercase the param
92             #pod }
93             #pod
94             #pod # Same method, same parameters, tweak the result
95             #pod sub method1 {
96             #pod my $self = shift;
97             #pod my $rv = $self->_OBJECT_->method1(@_);
98             #pod $rv =~ s/\n/
\n/g; # Add line-break HTML tags at each newline
99             #pod return $rv;
100             #pod }
101             #pod
102             #pod As you can see, the advantage of this full-scale I approach,
103             #pod compared to inheritance, or function wrapping (see L), is
104             #pod that you have complete and utter freedom to do anything you might need
105             #pod to do, without stressing the Perl inheritance model or doing anything
106             #pod unusual or tricky with C references.
107             #pod
108             #pod You may never need this much power. But when you need it, you B
109             #pod need it.
110             #pod
111             #pod As an aside, Class::Adapter::Clear is implemented with the following
112             #pod L formula.
113             #pod
114             #pod use Class::Adapter::Builder
115             #pod ISA => '_OBJECT_',
116             #pod AUTOLOAD => 1;
117             #pod
118             #pod =head1 METHODS
119             #pod
120             #pod =head2 new $object
121             #pod
122             #pod As does the base L class, the default C constructor
123             #pod takes a single object as argument and creates a new object which holds the
124             #pod passed object.
125             #pod
126             #pod Returns a new C object, or C if you do not pass
127             #pod in an object.
128             #pod
129             #pod =cut
130              
131 2     2   53283 use 5.005;
  2         12  
132 2     2   10 use strict;
  2         2  
  2         51  
133             use Class::Adapter::Builder
134 2         11 ISA => '_OBJECT_',
135 2     2   397 AUTOLOAD => 1;
  2         20  
136              
137             our $VERSION = '1.09';
138              
139             1;
140              
141             __END__