[Catalyst-commits] r8213 - in trunk/examples: . OAuthExample OAuthExample/lib OAuthExample/lib/OAuthExample OAuthExample/lib/OAuthExample/Controller OAuthExample/lib/OAuthExample/View OAuthExample/root OAuthExample/root/static OAuthExample/root/static/images OAuthExample/script OAuthExample/t

marcus at dev.catalyst.perl.org marcus at dev.catalyst.perl.org
Mon Aug 11 22:58:56 BST 2008


Author: marcus
Date: 2008-08-11 22:58:55 +0100 (Mon, 11 Aug 2008)
New Revision: 8213

Added:
   trunk/examples/OAuthExample/
   trunk/examples/OAuthExample/Changes
   trunk/examples/OAuthExample/Makefile.PL
   trunk/examples/OAuthExample/README
   trunk/examples/OAuthExample/lib/
   trunk/examples/OAuthExample/lib/OAuthExample.pm
   trunk/examples/OAuthExample/lib/OAuthExample/
   trunk/examples/OAuthExample/lib/OAuthExample/Controller/
   trunk/examples/OAuthExample/lib/OAuthExample/Controller/Root.pm
   trunk/examples/OAuthExample/lib/OAuthExample/Model/
   trunk/examples/OAuthExample/lib/OAuthExample/View/
   trunk/examples/OAuthExample/lib/OAuthExample/View/TT.pm
   trunk/examples/OAuthExample/oauthexample.conf
   trunk/examples/OAuthExample/root/
   trunk/examples/OAuthExample/root/default.tt
   trunk/examples/OAuthExample/root/favicon.ico
   trunk/examples/OAuthExample/root/static/
   trunk/examples/OAuthExample/root/static/images/
   trunk/examples/OAuthExample/root/static/images/btn_120x50_built.png
   trunk/examples/OAuthExample/root/static/images/btn_120x50_built_shadow.png
   trunk/examples/OAuthExample/root/static/images/btn_120x50_powered.png
   trunk/examples/OAuthExample/root/static/images/btn_120x50_powered_shadow.png
   trunk/examples/OAuthExample/root/static/images/btn_88x31_built.png
   trunk/examples/OAuthExample/root/static/images/btn_88x31_built_shadow.png
   trunk/examples/OAuthExample/root/static/images/btn_88x31_powered.png
   trunk/examples/OAuthExample/root/static/images/btn_88x31_powered_shadow.png
   trunk/examples/OAuthExample/root/static/images/catalyst_logo.png
   trunk/examples/OAuthExample/root/wrapper.tt
   trunk/examples/OAuthExample/script/
   trunk/examples/OAuthExample/script/oauthexample_cgi.pl
   trunk/examples/OAuthExample/script/oauthexample_create.pl
   trunk/examples/OAuthExample/script/oauthexample_fastcgi.pl
   trunk/examples/OAuthExample/script/oauthexample_server.pl
   trunk/examples/OAuthExample/script/oauthexample_test.pl
   trunk/examples/OAuthExample/t/
   trunk/examples/OAuthExample/t/01app.t
   trunk/examples/OAuthExample/t/02pod.t
   trunk/examples/OAuthExample/t/03podcoverage.t
   trunk/examples/OAuthExample/t/view_TT.t
Log:
Ported OAuth example from Net::OAuth to catalyst

Added: trunk/examples/OAuthExample/Changes
===================================================================
--- trunk/examples/OAuthExample/Changes	                        (rev 0)
+++ trunk/examples/OAuthExample/Changes	2008-08-11 21:58:55 UTC (rev 8213)
@@ -0,0 +1,4 @@
+This file documents the revision history for Perl extension OAuthExample.
+
+0.01  2008-08-11 21:09:39
+        - initial revision, generated by Catalyst

Added: trunk/examples/OAuthExample/Makefile.PL
===================================================================
--- trunk/examples/OAuthExample/Makefile.PL	                        (rev 0)
+++ trunk/examples/OAuthExample/Makefile.PL	2008-08-11 21:58:55 UTC (rev 8213)
@@ -0,0 +1,23 @@
+# IMPORTANT: if you delete this file your app will not work as
+# expected.  you have been warned
+use inc::Module::Install;
+
+name 'OAuthExample';
+all_from 'lib/OAuthExample.pm';
+
+requires 'Catalyst::Runtime' => '5.7014';
+requires 'Catalyst::Plugin::ConfigLoader';
+requires 'Catalyst::Plugin::Static::Simple';
+requires 'Catalyst::Action::RenderView';
+requires 'Catalyst::Plugin::Session::State::Cookie';
+requires 'Catalyst::Plugin::Session::Store::File';
+requires 'Net::OAuth';
+requires 'Data::Random';
+requires 'parent';
+requires 'Config::General'; # This should reflect the config file format you've chosen
+                 # See Catalyst::Plugin::ConfigLoader for supported formats
+catalyst;
+
+install_script glob('script/*.pl');
+auto_install;
+WriteAll;

Added: trunk/examples/OAuthExample/README
===================================================================
--- trunk/examples/OAuthExample/README	                        (rev 0)
+++ trunk/examples/OAuthExample/README	2008-08-11 21:58:55 UTC (rev 8213)
@@ -0,0 +1,15 @@
+First run perl Makefile.PL and make installdeps to make sure you have 
+the required modules
+
+To generate a certificate that matches the config replace the location string
+with something relevant for you:
+
+$ openssl req -x509 -nodes -days 365 -newkey rsa:1024 -sha1 -subj   '/C=NO/ST=OS/L=Oslo/CN=osx.iusethis.com' -keyout   myrsakey.pem -out myrsacert.pem
+
+Then go to 
+
+https://www.google.com/accounts/ManageDomains
+
+and add your domain and update the PEM certificate to google
+
+now run script/oauthexample_server.pl to test the application.

Added: trunk/examples/OAuthExample/lib/OAuthExample/Controller/Root.pm
===================================================================
--- trunk/examples/OAuthExample/lib/OAuthExample/Controller/Root.pm	                        (rev 0)
+++ trunk/examples/OAuthExample/lib/OAuthExample/Controller/Root.pm	2008-08-11 21:58:55 UTC (rev 8213)
@@ -0,0 +1,158 @@
+package OAuthExample::Controller::Root;
+
+use strict;
+use warnings;
+use parent 'Catalyst::Controller';
+
+use Net::OAuth;
+use LWP::UserAgent;
+use HTTP::Request::Common;
+use XML::LibXML;
+use XML::LibXML::XPathContext;
+use File::Spec;
+use List::Util 'shuffle';
+
+#
+# Sets the actions in this controller to be registered with no prefix
+# so they function identically to actions created in MyApp.pm
+#
+__PACKAGE__->config->{namespace} = '';
+
+=head1 NAME
+
+OAuthExample::Controller::Root - Root Controller for OAuthExample
+
+=head1 DESCRIPTION
+
+[enter your description here]
+
+=head1 METHODS
+
+=cut
+
+=head2 index
+
+=cut
+
+
+
+sub default : Path {
+    my ( $self, $c ) = @_;
+            if (defined $c->session->{token}) {
+                    my $request = Net::OAuth->request("protected resource")->new(
+                        $c->_default_request_params,
+                        request_url => $c->config->{contacts_feed_url},
+                        token => $c->session->{token},
+                        token_secret => '',
+                    );
+
+                    $request->sign($c->_get_key);
+
+                    my $ua = LWP::UserAgent->new;
+
+                    my $res = $ua->request(GET($request->request_url, 
+                        Authorization => $request->to_authorization_header));
+
+                    if (!$res->is_success) {
+                        die 'Could not get feed: ' . $res->status_line . ' ' . 
+                        $res->content;
+                    }
+
+                    my $parser = new XML::LibXML;
+                    my $doc = $parser->parse_string($res->content);
+                    my $xpc = XML::LibXML::XPathContext->new;
+                    $xpc->registerNs('atom', 'http://www.w3.org/2005/Atom');
+                    $c->stash->{contacts} = [ shuffle($xpc->findnodes('//atom:entry/atom:title', $doc))];
+
+            }    
+}
+
+sub login : Global {
+        my ( $self, $c ) = @_;
+
+        my $request = Net::OAuth->request("request token")->new(
+            $c->_default_request_params,
+            request_url => $c->config->{request_token_endpoint},
+            extra_params => {
+                scope=> $c->config->{request_scope},
+            }
+        );
+
+
+        $request->sign($c->_get_key);
+
+        my  $ua = LWP::UserAgent->new;
+
+        my $res = $ua->request(GET $request->to_url); 
+        # Post message to the Service Provider
+
+        if (!$res->is_success) {
+            die 'Could not get a Request Token: ' . $res->status_line . ' ' . $res->content;
+        }
+
+        my $response = Net::OAuth->response('request token')->from_post_body($res->content);
+    
+
+        $request = Net::OAuth->request('user auth')->new(
+            token => $response->token,
+            callback => $c->uri_for('/callback'),
+        );
+
+        return $c->res->redirect($request->to_url($c->config->{user_auth_endpoint}));
+}
+
+
+
+sub callback : Global {
+        my ( $self, $c ) = @_;
+        my $response = Net::OAuth->response('user auth')->from_hash($c->req->params);
+
+        my $request = Net::OAuth->request("access token")->new(
+            $c->_default_request_params,
+            request_url => $c->config->{access_token_endpoint},
+            token => $response->token,
+            token_secret => '',
+        );
+
+        $request->sign($c->_get_key);
+
+        my $ua = LWP::UserAgent->new;
+
+        my $res = $ua->request(GET $request->to_url); 
+        # Post message to the Service Provider
+
+        if (!$res->is_success) {
+            die 'Could not get an Access Token: ' . $res->status_line . ' ' . $res->content;
+        }
+
+        $response = Net::OAuth->response('access token')->from_post_body($res->content);
+        $c->session->{token}= $response->token;
+        $c->res->redirect($c->uri_for('/'));
+}
+
+sub logout : Global {
+    my ( $self, $c ) = @_;
+    undef $c->session->{token};
+    $c->res->redirect($c->uri_for('/'));
+}
+
+=head2 end
+
+Attempt to render a view, if needed.
+
+=cut 
+
+sub end : ActionClass('RenderView') {}
+
+=head1 AUTHOR
+
+Marcus Ramberg
+
+=head1 LICENSE
+
+This library is free software, you can redistribute it and/or modify
+it under the same terms as Perl itself.
+
+=cut
+
+1;

Added: trunk/examples/OAuthExample/lib/OAuthExample/View/TT.pm
===================================================================
--- trunk/examples/OAuthExample/lib/OAuthExample/View/TT.pm	                        (rev 0)
+++ trunk/examples/OAuthExample/lib/OAuthExample/View/TT.pm	2008-08-11 21:58:55 UTC (rev 8213)
@@ -0,0 +1,32 @@
+package OAuthExample::View::TT;
+
+use strict;
+use base 'Catalyst::View::TT';
+
+__PACKAGE__->config(TEMPLATE_EXTENSION => '.tt');
+__PACKAGE__->config(WRAPPER => 'wrapper.tt');
+
+=head1 NAME
+
+OAuthExample::View::TT - TT View for OAuthExample
+
+=head1 DESCRIPTION
+
+TT View for OAuthExample. 
+
+=head1 AUTHOR
+
+=head1 SEE ALSO
+
+L<OAuthExample>
+
+Marcus Ramberg
+
+=head1 LICENSE
+
+This library is free software, you can redistribute it and/or modify
+it under the same terms as Perl itself.
+
+=cut
+
+1;

Added: trunk/examples/OAuthExample/lib/OAuthExample.pm
===================================================================
--- trunk/examples/OAuthExample/lib/OAuthExample.pm	                        (rev 0)
+++ trunk/examples/OAuthExample/lib/OAuthExample.pm	2008-08-11 21:58:55 UTC (rev 8213)
@@ -0,0 +1,90 @@
+package OAuthExample;
+
+use strict;
+use warnings;
+
+use Catalyst::Runtime '5.70';
+
+# Set flags and add plugins for the application
+#
+#         -Debug: activates the debug mode for very useful log messages
+#   ConfigLoader: will load the configuration from a Config::General file in the
+#                 application's home directory
+# Static::Simple: will serve static files from the application's root 
+#                 directory
+
+use parent qw/Catalyst/;
+use Crypt::OpenSSL::RSA;
+use File::Slurp;
+use Data::Random qw(rand_chars);
+
+
+our $VERSION = '0.01';
+
+# Configure the application. 
+#
+# Note that settings in oauthexample.conf (or other external
+# configuration file that you set up manually) take precedence
+# over this when using ConfigLoader. Thus configuration
+# details given here can function as a default configuration,
+# with a external configuration file acting as an override for
+# local deployment.
+
+__PACKAGE__->config( name => 'OAuthExample' );
+
+# Start the application
+__PACKAGE__->setup(qw/-Debug 
+    ConfigLoader 
+    Static::Simple 
+    Session 
+    Session::State::Cookie
+    Session::Store::File/);
+
+
+sub _get_key {
+    my $c = shift;
+    my $ketstring = read_file($c->config->{private_key});
+    return Crypt::OpenSSL::RSA->new_private_key($ketstring);
+}
+
+sub _default_request_params {
+        my $c = shift;
+        return (
+                consumer_key => $c->config->{consumer_key},
+                consumer_secret => '',
+                request_method => 'GET',
+                signature_method => 'RSA-SHA1',
+                timestamp => time,
+                nonce => join('', rand_chars(size=>16, set=>'alphanumeric')),
+        );
+}
+
+
+=head1 NAME
+
+OAuthExample - Catalyst based application
+
+=head1 SYNOPSIS
+
+    script/oauthexample_server.pl
+
+=head1 DESCRIPTION
+
+[enter your description here]
+
+=head1 SEE ALSO
+
+L<OAuthExample::Controller::Root>, L<Catalyst>
+
+=head1 AUTHOR
+
+Marcus Ramberg
+
+=head1 LICENSE
+
+This library is free software, you can redistribute it and/or modify
+it under the same terms as Perl itself.
+
+=cut
+
+1;

Added: trunk/examples/OAuthExample/oauthexample.conf
===================================================================
--- trunk/examples/OAuthExample/oauthexample.conf	                        (rev 0)
+++ trunk/examples/OAuthExample/oauthexample.conf	2008-08-11 21:58:55 UTC (rev 8213)
@@ -0,0 +1,11 @@
+# rename this file to OAuthExample.yml and put a : in front of "name" if
+# you want to use yaml like in old versions of Catalyst
+name OAuthExample
+private_key myrsakey.pem
+consumer_key osx.iusethis.com
+# You probably dont need to change anything past this point
+contacts_feed_url http://www.google.com/m8/feeds/contacts/default/full
+request_token_endpoint https://www.google.com/accounts/OAuthGetRequestToken
+user_auth_endpoint https://www.google.com/accounts/OAuthAuthorizeToken
+request_scope http://www.google.com/m8/feeds
+access_token_endpoint https://www.google.com/accounts/OAuthGetAccessToken
\ No newline at end of file

Added: trunk/examples/OAuthExample/root/default.tt
===================================================================
--- trunk/examples/OAuthExample/root/default.tt	                        (rev 0)
+++ trunk/examples/OAuthExample/root/default.tt	2008-08-11 21:58:55 UTC (rev 8213)
@@ -0,0 +1,38 @@
+<p>Hello.  This page demonstrates the <a href="http://oauth.net">OAuth protocol</a>.  It uses OAuth to access the <a href="http://groups.google.com/group/oauth/browse_thread/thread/75ee6d973930c791/48f75bfdc1603b7c">Google Contacts API</a>.</p>
+
+[% IF c.session.errors.size %]
+<p style="color:red">
+[% FOREACH error IN c.session.errors %]
+[% error %] <br />
+[% END %]
+</p>
+[% SET c.session.errors=undef %]
+[% END %]
+
+[% IF c.session.token %]
+
+<p style="color:green">Got Access Token <a href="[% c.uri_for('/logout')%]">[Reset]</a></p>
+
+[% IF contacts.size %]
+
+<p>Contacts retrieved successfully!  Here is a random selection:</p>
+
+<ul>
+[% FOREACH item IN contacts %]
+<li>
+[% item.textContent %]
+[% BREAK IF loop.count > 10 %]
+</li>
+[% END %]
+</ul>
+[% ELSE %]
+
+<p>No contacts found</p>
+
+[% END %]
+
+
+[% ELSE %]
+<p><a href="[% c.uri_for('/login') %]">Click here to begin</a></p>
+[% END %]
+

Added: trunk/examples/OAuthExample/root/favicon.ico
===================================================================
(Binary files differ)


Property changes on: trunk/examples/OAuthExample/root/favicon.ico
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: trunk/examples/OAuthExample/root/static/images/btn_120x50_built.png
===================================================================
(Binary files differ)


Property changes on: trunk/examples/OAuthExample/root/static/images/btn_120x50_built.png
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: trunk/examples/OAuthExample/root/static/images/btn_120x50_built_shadow.png
===================================================================
(Binary files differ)


Property changes on: trunk/examples/OAuthExample/root/static/images/btn_120x50_built_shadow.png
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: trunk/examples/OAuthExample/root/static/images/btn_120x50_powered.png
===================================================================
(Binary files differ)


Property changes on: trunk/examples/OAuthExample/root/static/images/btn_120x50_powered.png
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: trunk/examples/OAuthExample/root/static/images/btn_120x50_powered_shadow.png
===================================================================
(Binary files differ)


Property changes on: trunk/examples/OAuthExample/root/static/images/btn_120x50_powered_shadow.png
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: trunk/examples/OAuthExample/root/static/images/btn_88x31_built.png
===================================================================
(Binary files differ)


Property changes on: trunk/examples/OAuthExample/root/static/images/btn_88x31_built.png
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: trunk/examples/OAuthExample/root/static/images/btn_88x31_built_shadow.png
===================================================================
(Binary files differ)


Property changes on: trunk/examples/OAuthExample/root/static/images/btn_88x31_built_shadow.png
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: trunk/examples/OAuthExample/root/static/images/btn_88x31_powered.png
===================================================================
(Binary files differ)


Property changes on: trunk/examples/OAuthExample/root/static/images/btn_88x31_powered.png
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: trunk/examples/OAuthExample/root/static/images/btn_88x31_powered_shadow.png
===================================================================
(Binary files differ)


Property changes on: trunk/examples/OAuthExample/root/static/images/btn_88x31_powered_shadow.png
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: trunk/examples/OAuthExample/root/static/images/catalyst_logo.png
===================================================================
(Binary files differ)


Property changes on: trunk/examples/OAuthExample/root/static/images/catalyst_logo.png
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: trunk/examples/OAuthExample/root/wrapper.tt
===================================================================
--- trunk/examples/OAuthExample/root/wrapper.tt	                        (rev 0)
+++ trunk/examples/OAuthExample/root/wrapper.tt	2008-08-11 21:58:55 UTC (rev 8213)
@@ -0,0 +1,24 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+        <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
+
+        <title>OAuth Demo</title>
+
+        <style type="text/css">
+                body {font-family: Helvetica, Arial, sans}
+        </style>
+</head>
+
+<body>
+<h1>OAuth Demo</h1>
+[% content %]
+<br style="margin: 2em 0" />
+<cite style="font-size: smaller">OAuth demo by <a href="http://twitter.com/keeth">Keith Grennan</a>.  Powered by <a href="http://search.cpan.org/perldoc?Net::OAuth">Net::OAuth</a>. <br/>
+    
+     Ported to Catalyst by Marcus Ramberg. Get the <a href="http://dev.catalyst.perl.org/repos/Catalyst/trunk/examples/OAuthExample">source</a>.</cite>
+
+</body>
+</html>
\ No newline at end of file

Added: trunk/examples/OAuthExample/script/oauthexample_cgi.pl
===================================================================
--- trunk/examples/OAuthExample/script/oauthexample_cgi.pl	                        (rev 0)
+++ trunk/examples/OAuthExample/script/oauthexample_cgi.pl	2008-08-11 21:58:55 UTC (rev 8213)
@@ -0,0 +1,37 @@
+#!/usr/bin/perl -w
+
+BEGIN { $ENV{CATALYST_ENGINE} ||= 'CGI' }
+
+use strict;
+use warnings;
+use FindBin;
+use lib "$FindBin::Bin/../lib";
+use OAuthExample;
+
+OAuthExample->run;
+
+1;
+
+=head1 NAME
+
+oauthexample_cgi.pl - Catalyst CGI
+
+=head1 SYNOPSIS
+
+See L<Catalyst::Manual>
+
+=head1 DESCRIPTION
+
+Run a Catalyst application as a cgi script.
+
+=head1 AUTHOR
+
+Sebastian Riedel, C<sri at oook.de>
+
+=head1 COPYRIGHT
+
+
+This library is free software, you can redistribute it and/or modify
+it under the same terms as Perl itself.
+
+=cut


Property changes on: trunk/examples/OAuthExample/script/oauthexample_cgi.pl
___________________________________________________________________
Name: svn:executable
   + *

Added: trunk/examples/OAuthExample/script/oauthexample_create.pl
===================================================================
--- trunk/examples/OAuthExample/script/oauthexample_create.pl	                        (rev 0)
+++ trunk/examples/OAuthExample/script/oauthexample_create.pl	2008-08-11 21:58:55 UTC (rev 8213)
@@ -0,0 +1,75 @@
+#!/usr/bin/perl -w
+
+use strict;
+use warnings;
+use Getopt::Long;
+use Pod::Usage;
+use Catalyst::Helper;
+
+my $force = 0;
+my $mech  = 0;
+my $help  = 0;
+
+GetOptions(
+    'nonew|force'    => \$force,
+    'mech|mechanize' => \$mech,
+    'help|?'         => \$help
+ );
+
+pod2usage(1) if ( $help || !$ARGV[0] );
+
+my $helper = Catalyst::Helper->new( { '.newfiles' => !$force, mech => $mech } );
+
+pod2usage(1) unless $helper->mk_component( 'OAuthExample', @ARGV );
+
+1;
+
+=head1 NAME
+
+oauthexample_create.pl - Create a new Catalyst Component
+
+=head1 SYNOPSIS
+
+oauthexample_create.pl [options] model|view|controller name [helper] [options]
+
+ Options:
+   -force        don't create a .new file where a file to be created exists
+   -mechanize    use Test::WWW::Mechanize::Catalyst for tests if available
+   -help         display this help and exits
+
+ Examples:
+   oauthexample_create.pl controller My::Controller
+   oauthexample_create.pl controller My::Controller BindLex
+   oauthexample_create.pl -mechanize controller My::Controller
+   oauthexample_create.pl view My::View
+   oauthexample_create.pl view MyView TT
+   oauthexample_create.pl view TT TT
+   oauthexample_create.pl model My::Model
+   oauthexample_create.pl model SomeDB DBIC::Schema MyApp::Schema create=dynamic\
+   dbi:SQLite:/tmp/my.db
+   oauthexample_create.pl model AnotherDB DBIC::Schema MyApp::Schema create=static\
+   dbi:Pg:dbname=foo root 4321
+
+ See also:
+   perldoc Catalyst::Manual
+   perldoc Catalyst::Manual::Intro
+
+=head1 DESCRIPTION
+
+Create a new Catalyst Component.
+
+Existing component files are not overwritten.  If any of the component files
+to be created already exist the file will be written with a '.new' suffix.
+This behavior can be suppressed with the C<-force> option.
+
+=head1 AUTHOR
+
+Sebastian Riedel, C<sri at oook.de>
+Maintained by the Catalyst Core Team.
+
+=head1 COPYRIGHT
+
+This library is free software, you can redistribute it and/or modify
+it under the same terms as Perl itself.
+
+=cut


Property changes on: trunk/examples/OAuthExample/script/oauthexample_create.pl
___________________________________________________________________
Name: svn:executable
   + *

Added: trunk/examples/OAuthExample/script/oauthexample_fastcgi.pl
===================================================================
--- trunk/examples/OAuthExample/script/oauthexample_fastcgi.pl	                        (rev 0)
+++ trunk/examples/OAuthExample/script/oauthexample_fastcgi.pl	2008-08-11 21:58:55 UTC (rev 8213)
@@ -0,0 +1,80 @@
+#!/usr/bin/perl -w
+
+BEGIN { $ENV{CATALYST_ENGINE} ||= 'FastCGI' }
+
+use strict;
+use warnings;
+use Getopt::Long;
+use Pod::Usage;
+use FindBin;
+use lib "$FindBin::Bin/../lib";
+use OAuthExample;
+
+my $help = 0;
+my ( $listen, $nproc, $pidfile, $manager, $detach, $keep_stderr );
+ 
+GetOptions(
+    'help|?'      => \$help,
+    'listen|l=s'  => \$listen,
+    'nproc|n=i'   => \$nproc,
+    'pidfile|p=s' => \$pidfile,
+    'manager|M=s' => \$manager,
+    'daemon|d'    => \$detach,
+    'keeperr|e'   => \$keep_stderr,
+);
+
+pod2usage(1) if $help;
+
+OAuthExample->run( 
+    $listen, 
+    {   nproc   => $nproc,
+        pidfile => $pidfile, 
+        manager => $manager,
+        detach  => $detach,
+	keep_stderr => $keep_stderr,
+    }
+);
+
+1;
+
+=head1 NAME
+
+oauthexample_fastcgi.pl - Catalyst FastCGI
+
+=head1 SYNOPSIS
+
+oauthexample_fastcgi.pl [options]
+ 
+ Options:
+   -? -help      display this help and exits
+   -l -listen    Socket path to listen on
+                 (defaults to standard input)
+                 can be HOST:PORT, :PORT or a
+                 filesystem path
+   -n -nproc     specify number of processes to keep
+                 to serve requests (defaults to 1,
+                 requires -listen)
+   -p -pidfile   specify filename for pid file
+                 (requires -listen)
+   -d -daemon    daemonize (requires -listen)
+   -M -manager   specify alternate process manager
+                 (FCGI::ProcManager sub-class)
+                 or empty string to disable
+   -e -keeperr   send error messages to STDOUT, not
+                 to the webserver
+
+=head1 DESCRIPTION
+
+Run a Catalyst application as fastcgi.
+
+=head1 AUTHOR
+
+Sebastian Riedel, C<sri at oook.de>
+Maintained by the Catalyst Core Team.
+
+=head1 COPYRIGHT
+
+This library is free software, you can redistribute it and/or modify
+it under the same terms as Perl itself.
+
+=cut


Property changes on: trunk/examples/OAuthExample/script/oauthexample_fastcgi.pl
___________________________________________________________________
Name: svn:executable
   + *

Added: trunk/examples/OAuthExample/script/oauthexample_server.pl
===================================================================
--- trunk/examples/OAuthExample/script/oauthexample_server.pl	                        (rev 0)
+++ trunk/examples/OAuthExample/script/oauthexample_server.pl	2008-08-11 21:58:55 UTC (rev 8213)
@@ -0,0 +1,115 @@
+#!/usr/bin/perl -w
+
+BEGIN { 
+    $ENV{CATALYST_ENGINE} ||= 'HTTP';
+    $ENV{CATALYST_SCRIPT_GEN} = 31;
+    require Catalyst::Engine::HTTP;
+}  
+
+use strict;
+use warnings;
+use Getopt::Long;
+use Pod::Usage;
+use FindBin;
+use lib "$FindBin::Bin/../lib";
+
+my $debug             = 0;
+my $fork              = 0;
+my $help              = 0;
+my $host              = undef;
+my $port              = $ENV{OAUTHEXAMPLE_PORT} || $ENV{CATALYST_PORT} || 3000;
+my $keepalive         = 0;
+my $restart           = $ENV{OAUTHEXAMPLE_RELOAD} || $ENV{CATALYST_RELOAD} || 0;
+my $restart_delay     = 1;
+my $restart_regex     = '(?:/|^)(?!\.#).+(?:\.yml$|\.yaml$|\.conf|\.pm)$';
+my $restart_directory = undef;
+my $follow_symlinks   = 0;
+
+my @argv = @ARGV;
+
+GetOptions(
+    'debug|d'             => \$debug,
+    'fork'                => \$fork,
+    'help|?'              => \$help,
+    'host=s'              => \$host,
+    'port=s'              => \$port,
+    'keepalive|k'         => \$keepalive,
+    'restart|r'           => \$restart,
+    'restartdelay|rd=s'   => \$restart_delay,
+    'restartregex|rr=s'   => \$restart_regex,
+    'restartdirectory=s@' => \$restart_directory,
+    'followsymlinks'      => \$follow_symlinks,
+);
+
+pod2usage(1) if $help;
+
+if ( $restart && $ENV{CATALYST_ENGINE} eq 'HTTP' ) {
+    $ENV{CATALYST_ENGINE} = 'HTTP::Restarter';
+}
+if ( $debug ) {
+    $ENV{CATALYST_DEBUG} = 1;
+}
+
+# This is require instead of use so that the above environment
+# variables can be set at runtime.
+require OAuthExample;
+
+OAuthExample->run( $port, $host, {
+    argv              => \@argv,
+    'fork'            => $fork,
+    keepalive         => $keepalive,
+    restart           => $restart,
+    restart_delay     => $restart_delay,
+    restart_regex     => qr/$restart_regex/,
+    restart_directory => $restart_directory,
+    follow_symlinks   => $follow_symlinks,
+} );
+
+1;
+
+=head1 NAME
+
+oauthexample_server.pl - Catalyst Testserver
+
+=head1 SYNOPSIS
+
+oauthexample_server.pl [options]
+
+ Options:
+   -d -debug          force debug mode
+   -f -fork           handle each request in a new process
+                      (defaults to false)
+   -? -help           display this help and exits
+      -host           host (defaults to all)
+   -p -port           port (defaults to 3000)
+   -k -keepalive      enable keep-alive connections
+   -r -restart        restart when files get modified
+                      (defaults to false)
+   -rd -restartdelay  delay between file checks
+   -rr -restartregex  regex match files that trigger
+                      a restart when modified
+                      (defaults to '\.yml$|\.yaml$|\.conf|\.pm$')
+   -restartdirectory  the directory to search for
+                      modified files, can be set mulitple times
+                      (defaults to '[SCRIPT_DIR]/..')
+   -follow_symlinks   follow symlinks in search directories
+                      (defaults to false. this is a no-op on Win32)
+ See also:
+   perldoc Catalyst::Manual
+   perldoc Catalyst::Manual::Intro
+
+=head1 DESCRIPTION
+
+Run a Catalyst Testserver for this application.
+
+=head1 AUTHOR
+
+Sebastian Riedel, C<sri at oook.de>
+Maintained by the Catalyst Core Team.
+
+=head1 COPYRIGHT
+
+This library is free software, you can redistribute it and/or modify
+it under the same terms as Perl itself.
+
+=cut


Property changes on: trunk/examples/OAuthExample/script/oauthexample_server.pl
___________________________________________________________________
Name: svn:executable
   + *

Added: trunk/examples/OAuthExample/script/oauthexample_test.pl
===================================================================
--- trunk/examples/OAuthExample/script/oauthexample_test.pl	                        (rev 0)
+++ trunk/examples/OAuthExample/script/oauthexample_test.pl	2008-08-11 21:58:55 UTC (rev 8213)
@@ -0,0 +1,54 @@
+#!/usr/bin/perl -w
+
+use strict;
+use warnings;
+use Getopt::Long;
+use Pod::Usage;
+use FindBin;
+use lib "$FindBin::Bin/../lib";
+use Catalyst::Test 'OAuthExample';
+
+my $help = 0;
+
+GetOptions( 'help|?' => \$help );
+
+pod2usage(1) if ( $help || !$ARGV[0] );
+
+print request($ARGV[0])->content . "\n";
+
+1;
+
+=head1 NAME
+
+oauthexample_test.pl - Catalyst Test
+
+=head1 SYNOPSIS
+
+oauthexample_test.pl [options] uri
+
+ Options:
+   -help    display this help and exits
+
+ Examples:
+   oauthexample_test.pl http://localhost/some_action
+   oauthexample_test.pl /some_action
+
+ See also:
+   perldoc Catalyst::Manual
+   perldoc Catalyst::Manual::Intro
+
+=head1 DESCRIPTION
+
+Run a Catalyst action from the command line.
+
+=head1 AUTHOR
+
+Sebastian Riedel, C<sri at oook.de>
+Maintained by the Catalyst Core Team.
+
+=head1 COPYRIGHT
+
+This library is free software, you can redistribute it and/or modify
+it under the same terms as Perl itself.
+
+=cut


Property changes on: trunk/examples/OAuthExample/script/oauthexample_test.pl
___________________________________________________________________
Name: svn:executable
   + *

Added: trunk/examples/OAuthExample/t/01app.t
===================================================================
--- trunk/examples/OAuthExample/t/01app.t	                        (rev 0)
+++ trunk/examples/OAuthExample/t/01app.t	2008-08-11 21:58:55 UTC (rev 8213)
@@ -0,0 +1,7 @@
+use strict;
+use warnings;
+use Test::More tests => 2;
+
+BEGIN { use_ok 'Catalyst::Test', 'OAuthExample' }
+
+ok( request('/')->is_success, 'Request should succeed' );

Added: trunk/examples/OAuthExample/t/02pod.t
===================================================================
--- trunk/examples/OAuthExample/t/02pod.t	                        (rev 0)
+++ trunk/examples/OAuthExample/t/02pod.t	2008-08-11 21:58:55 UTC (rev 8213)
@@ -0,0 +1,9 @@
+use strict;
+use warnings;
+use Test::More;
+
+eval "use Test::Pod 1.14";
+plan skip_all => 'Test::Pod 1.14 required' if $@;
+plan skip_all => 'set TEST_POD to enable this test' unless $ENV{TEST_POD};
+
+all_pod_files_ok();

Added: trunk/examples/OAuthExample/t/03podcoverage.t
===================================================================
--- trunk/examples/OAuthExample/t/03podcoverage.t	                        (rev 0)
+++ trunk/examples/OAuthExample/t/03podcoverage.t	2008-08-11 21:58:55 UTC (rev 8213)
@@ -0,0 +1,9 @@
+use strict;
+use warnings;
+use Test::More;
+
+eval "use Test::Pod::Coverage 1.04";
+plan skip_all => 'Test::Pod::Coverage 1.04 required' if $@;
+plan skip_all => 'set TEST_POD to enable this test' unless $ENV{TEST_POD};
+
+all_pod_coverage_ok();

Added: trunk/examples/OAuthExample/t/view_TT.t
===================================================================
--- trunk/examples/OAuthExample/t/view_TT.t	                        (rev 0)
+++ trunk/examples/OAuthExample/t/view_TT.t	2008-08-11 21:58:55 UTC (rev 8213)
@@ -0,0 +1,6 @@
+use strict;
+use warnings;
+use Test::More tests => 1;
+
+BEGIN { use_ok 'OAuthExample::View::TT' }
+




More information about the Catalyst-commits mailing list