| 1 | package WWW::Pipeline::Example; | ||
| 2 | $VERSION = '0.1'; | ||
| 3 | |||
| 4 | use base 'WWW::Pipeline'; | ||
| 5 | |||
| 6 | =head1 WWW::Pipeline::Example | ||
| 7 | |||
| 8 | This module is a simple example application to demonstrate the very basic | ||
| 9 | pieces of building an application with WWW::Pipeline. In order to run this | ||
| 10 | application, create an instance script that looks like the following: | ||
| 11 | |||
| 12 | #!/usr/bin/perl | ||
| 13 | |||
| 14 | use strict; | ||
| 15 | use warnings; | ||
| 16 | |||
| 17 | use WWW::Pipeline::Example; | ||
| 18 | |||
| 19 | my $application = WWW::Pipeline::Example->new(); | ||
| 20 | $application->run(); | ||
| 21 | |||
| 22 | exit(0); | ||
| 23 | |||
| 24 | Give it the appropriate executable permissions and place it in a web-accessible | ||
| 25 | directory. Assuming everything has been set correctly, pointing your browser | ||
| 26 | at the script should give you access to a very simple two page application. | ||
| 27 | |||
| 28 | =cut | ||
| 29 | |||
| 30 | #-- pragmas ---------------------------- | ||
| 31 | use strict; | ||
| 32 | use warnings; | ||
| 33 | |||
| 34 | #=============================================================================== | ||
| 35 | |||
| 36 | =head2 the C<%plan> | ||
| 37 | |||
| 38 | For this application we've set up two handlers. During the Initialization | ||
| 39 | Phase, we've registered the C<_setup> method. During the ParseRequest Phase, | ||
| 40 | we've added the C<_grepMode> method. Other phases of the pipeline are populated | ||
| 41 | by a few plugins we load in the C<_setup> method. | ||
| 42 | |||
| 43 | =cut | ||
| 44 | |||
| 45 | our %plan = ( | ||
| 46 | Initialization => [ \&_setup ], | ||
| 47 | ParseRequest => [ \&_grepMode ], | ||
| 48 | ); | ||
| 49 | |||
| 50 | #== Handlers =================================================================== | ||
| 51 | |||
| 52 | =head2 the Handlers | ||
| 53 | |||
| 54 | =head3 _setup | ||
| 55 | |||
| 56 | During the C<_setup> method we load the plugins C<CGISimple>, C<RunModes>, and | ||
| 57 | C<Output>. C<CGISimple> gives us a query() method which returns a CGI::Simple | ||
| 58 | instance. C<RunModes> provides an easy way to manage the multiple screens that | ||
| 59 | need to be generated for the typical web application. C<Output> provides means | ||
| 60 | for setting http headers and sending the formulated response back to the client. | ||
| 61 | |||
| 62 | Once we've got RunModes loaded we also take this opportunity to tell our | ||
| 63 | application which run modes this application will have. The two implemented | ||
| 64 | run modes are described later. | ||
| 65 | |||
| 66 | =cut | ||
| 67 | |||
| 68 | sub _setup { | ||
| 69 | my $self = shift; | ||
| 70 | $self->loadPlugins( qw( CGISimple RunModes Output ) ); | ||
| 71 | |||
| 72 | $self->run_modes( | ||
| 73 | start => \&start, | ||
| 74 | next => 'next' | ||
| 75 | ); | ||
| 76 | |||
| 77 | $self->mode('start'); | ||
| 78 | } | ||
| 79 | |||
| 80 | #------------------------------------------------------------------------------- | ||
| 81 | |||
| 82 | =head3 _grepMode | ||
| 83 | |||
| 84 | The C<_grepMode> method is run during the ParseRequest phase of the pipeline, | ||
| 85 | and looks for the query parameter 'op' to tell the application which run mode | ||
| 86 | it should run. | ||
| 87 | |||
| 88 | =cut | ||
| 89 | |||
| 90 | sub _grepMode { | ||
| 91 | my $self = shift; | ||
| 92 | $self->mode( $self->query->param('op') ); | ||
| 93 | } | ||
| 94 | |||
| 95 | #== Run Modes ================================================================== | ||
| 96 | |||
| 97 | =head2 Run Modes | ||
| 98 | |||
| 99 | Since we're using the C<RunModes> plugin to manage our application state for any | ||
| 100 | given request, we have defined two run modes, C<start> and C<next>. Each | ||
| 101 | generate a simple html page with a link to the other. They link to each other | ||
| 102 | by defining the C<op> parameter in the url's query string, which is picked up | ||
| 103 | by the application's C<_grepMode> handler to determine which page should be | ||
| 104 | generated. | ||
| 105 | |||
| 106 | =cut | ||
| 107 | |||
| 108 | sub start { | ||
| 109 | |||
| 110 | return qq( | ||
| 111 | hello world, this is the start page<br /> | ||
| 112 | <a href="example.cgi?op=next" >next</a> | ||
| 113 | ); | ||
| 114 | } | ||
| 115 | |||
| 116 | #------------------------------------------------------------------------------- | ||
| 117 | sub next { | ||
| 118 | |||
| 119 | return qq( | ||
| 120 | hello world, this is the next page<br /> | ||
| 121 | <a href="example.cgi?op=start" >back to start</a> | ||
| 122 | ); | ||
| 123 | } | ||
| 124 | |||
| 125 | #======== | ||
| 126 | 1; | ||
| 127 | |||
| 128 | =head2 See Also | ||
| 129 | |||
| 130 | WWW::Pipeline | ||
| 131 | Application::Pipeline | ||
| 132 | |||
| 133 | WWW::Pipeline::Services::RunModes | ||
| 134 | WWW::Pipeline::Services::Output | ||
| 135 | WWW::Pipeline::Services::CGISimple | ||
| 136 | |||
| 137 | CGI::Application | ||
| 138 | |||
| 139 | =head2 Authors | ||
| 140 | |||
| 141 | Stephen Howard <stephen@thunkit.com> | ||
| 142 | |||
| 143 | =head2 License | ||
| 144 | |||
| 145 | This module may be distributed under the same terms as Perl itself. | ||
| 146 | |||
| 147 | =cut |