Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added Squatting/Cookbook.pod

  • Loading branch information...
commit 3a45cf788e932bfa8cb2eb7b0f5cf8b0cce6a959 1 parent 5308e65
John Beppu authored
View
3  MANIFEST
@@ -13,6 +13,7 @@ etc/init.d/squatting-gentoo
etc/init.d/squatting-ubuntu
lib/Squatting.pm
lib/Squatting/Controller.pm
+lib/Squatting/Cookbook.pod
lib/Squatting/Mapper.pm
lib/Squatting/Q.pm
lib/Squatting/View.pm
@@ -22,3 +23,5 @@ MANIFEST.SKIP
MIT-LICENSE
README
t/00_basic.t
+t/01_controller.t
+t/02_view.t
View
2  eg/Example.pm
@@ -2,4 +2,6 @@ package Example;
use base 'Squatting';
use Example::Controllers;
use Example::Views;
+use PODServer;
+Example->mount('PODServer', '/pod');
1;
View
3  eg/Example/Controllers.pm
@@ -91,8 +91,9 @@ our @C = (
# The generic template, '_', is used
# when no other template can be found.
}
- )
+ ),
);
+
1;
View
75 lib/Squatting.pm
@@ -87,22 +87,45 @@ sub import {
}
}
+# App->mount($AnotherApp, $prefix) # Map another app on to a URL $prefix.
+sub mount {
+ my ($app, $other, $prefix) = @_;
+ push @{$app."::O"}, $other;
+ push @{$app."::Controllers::C"}, map {
+ my $urls = $_->urls;
+ $_->urls = [ map { $prefix.$_ } @$urls ];
+ $_;
+ } @{$other."::Controllers::C"}
+}
+
+# App->init # Initialize $app
+sub init {
+ $_->init for (@{$_[0]."::O"});
+ %{$_[0]."::Controllers::C"} = map { $_->name => $_ }
+ @{$_[0]."::Controllers::C"};
+ %{$_[0]."::Views::V"} = map { $_->name => $_ }
+ @{$_[0]."::Views::V"};
+}
+
# App->service($controller, @params) # Override this method if you want to take actions before or after a request is handled.
sub service {
my ($app, $c, @params) = grep { defined } @_;
my $method = lc $c->env->{REQUEST_METHOD};
my $content;
- $I++;
+
eval { $content = $c->$method(@params) };
warn "EXCEPTION: $@" if ($@);
+
+ # TODO - move this code into another (optional) module. {{{
+ $I++;
my $s = $c->status;
- my $cookies = $c->cookies;
my $ppi = (%{$c->input})
? ', ' . pp($c->input)
: '';
- #
warn sprintf('%5d ', $I), "[$s] $app->$method(@{[ join(', '=>map { \"'$_'\" } $c->name, @params) ]}$ppi)\n";
- #
+ # }}}
+
+ my $cookies = $c->cookies;
$c->headers->{'Set-Cookie'} = join("; ",
map { CGI::Cookie->new( -name => $_, %{$cookies->{$_}} ) }
grep { ref $cookies->{$_} eq 'HASH' }
@@ -115,14 +138,6 @@ sub service {
return $content;
}
-# App->init # Initialize $app
-sub init {
- %{$_[0]."::Controllers::C"} = map { $_->name => $_ }
- @{$_[0]."::Controllers::C"};
- %{$_[0]."::Views::V"} = map { $_->name => $_ }
- @{$_[0]."::Views::V"};
-}
-
# App->go(%opts) # Start the server.
sub go {
my $app = shift;
@@ -265,18 +280,34 @@ The View API feels like Camping, but Squatting allows multiple views to coexist
=item B<Minimal Policy>
-You may use any templating system you want, and you may use any ORM(*) you want.
-We only have a few rules on how the controller code and the view code should be
-organized, but beyond that, you are free.
-
-=back
+You may use any templating system you want, and you may use any ORM(*) you
+want. We only have a few rules on how the controller code and the view code
+should be organized, but beyond that, you are free.
-* Regarding ORMs, the nature of Continuity makes it somewhat DBI-unfriendly, so
+* Regarding ORMs, the nature of Continuity** makes it somewhat DBI-unfriendly, so
this may be a deal-breaker for many of you. However, I look at this as an
opportunity to try novel storage systems like CouchDB, instead. With the high
level of concurrency that Squatting can support (thanks to Continuity) we are
probably better off this way.
+** If you're not using Continuity, then really feel free to use any ORM.
+
+=item B<Squatting Apps Are Composable>
+
+You can take multiple Squatting apps and compose them into a single app. For
+example, suppose you built a site and decided that you'd like to add a forum.
+You could take a hypothetical forum app written in Squatting and just mount
+it at an arbitrary path like /forum.
+
+=item B<Squatting Apps Are Embeddable>
+
+Already using another framework? No problem. You should be able to embed
+Squatting apps into apps written in anything from CGI on up to Catalyst.
+(The documentation for this will be written soon.)
+
+=back
+
+
=head1 API
=head2 Use as a Base Class for Squatting Applications
@@ -299,6 +330,14 @@ this is the method you should override in your subclass.
This method takes no parameters and initializes some internal variables.
+=head3 App->mount($AnotherApp, $prefix)
+
+This method will mount another Squatting app at the specified prefix.
+
+ App->mount('My::Blog', '/my/ridiculous/rantings');
+ App->mount('Forum', '/forum');
+ App->mount('ChatterBox', '/chat');
+
=head3 App->go(%options)
This method calls init and then starts a Continuity-based web server. The %options
View
52 lib/Squatting/Cookbook.pod
@@ -0,0 +1,52 @@
+=head1 NAME
+
+Squatting::Cookbook - Techniques
+
+=head1 INTRODUCTION
+
+(This is a work in progress....)
+
+=head2 Anatomy of a Squatting Application
+
+
+=head1 TECHNIQUES
+
+=head2 COMET
+
+=head3 Event Architecture
+
+The L<Continuity> backend is the only one that will allow you to do COMET.
+
+
+=head2 How to use various templating systems with Squatting
+
+=head3 HTML::AsSubs
+
+=head3 Tenjin
+
+=head3 Template::Toolkit
+
+=head3 HTML::Mason
+
+=head3 HTML::Template
+
+
+=head2 How to compose multiple Squatting apps into one app
+
+
+=head2 How to embed a Squatting app into other frameworks
+
+=head3 Catalyst
+
+=head3 HTML::Mason
+
+=head3 CGI
+
+
+=head1 DEPLOYMENT
+
+=head3 mod_perl1
+
+=head3 mod_perl2
+
+=cut
Please sign in to comment.
Something went wrong with that request. Please try again.