Skip to content
This repository

A Camping-inspired Web Microframework for Perl

branch: master

Checking in changes prior to tagging of version 0.82.

Changelog diff is:

diff --git a/Changes b/Changes
index 88f36c1..d165440 100644
--- a/Changes
+++ b/Changes
@@ -17,11 +17,12 @@ Beyond (unreleased)
       - PSGI support by default
   * Replace Shell::Perl with something based on Eval::WithLexicals.

-0.82 unreleased
+0.82 2013-08-11
   - Squatting::With::PerHostConfig was removed, because I realized
     that it couldn't work the way I wanted it, too.  By the time
     it modified %CONFIG, it would be too late to affect the response
     in a meaningful way.
+  - Small patch from Duncan Garland to remove warnings issued by perl 5.14

 0.81 2011-04-27
   - Slight improvements to Squatting::With::MockRequest were made
latest commit bcac4f5b73
John Beppu authored August 11, 2013
Octocat-spinner-32 bin preload Squatting so I can print $Squatting::VERSION April 16, 2011
Octocat-spinner-32 doc someday, i may give a lightning talk on squatting December 10, 2008
Octocat-spinner-32 eg learned how to make encode_base64 not emit an extra newline April 09, 2011
Octocat-spinner-32 lib Checking in changes prior to tagging of version 0.82. August 11, 2013
Octocat-spinner-32 t bug fixes to my previous attempt removing extra use statements September 27, 2010
Octocat-spinner-32 xt xt/ tests September 09, 2010
Octocat-spinner-32 .gitignore more files to .gitignore April 28, 2008
Octocat-spinner-32 .shipit shipit config August 24, 2009
Octocat-spinner-32 Changes Checking in changes prior to tagging of version 0.82. August 11, 2013
Octocat-spinner-32 EARLY_NOTES redid the README June 15, 2011
Octocat-spinner-32 MANIFEST Checking in changes prior to tagging of version 0.82. August 11, 2013
Octocat-spinner-32 MANIFEST.SKIP Ignore .git/**/* April 26, 2008
Octocat-spinner-32 MIT-LICENSE Back to MIT May 13, 2008
Octocat-spinner-32 Makefile.PL Upgrade Makefile.PL January 03, 2010
Octocat-spinner-32 README redid the README June 15, 2011
Octocat-spinner-32 edit removed references to Squatting::Cookbook February 08, 2011
README

                                                                  -+m
                                                                 .%- ..
  [ Squatting ]                                                . m*#-+ 
  A Camping-inspired Web Microframework for Perl               m+*##+m.
                                                          ...- m#*#%-..
                                                        --.. +mm###-+-.
                                                      ..- m..*#####*m++
                                                   .--+.-m#m+.%+-m###+
                                                  .-m..###+...% m#m-##% .
                                                     +%+.. -++.+  m--#-+
                                                  .. --..%*-%-    --+#.m
                                                   -  - -.--+# ..   +#m+
                                                        ..#-+%.    +.#..
                                           .    . .    .%#-...     .-+.-
                                   .   -.+m+-. .. .-.++#.*-...       . .
                           ..- .+. ..+..+---+%---.--.--#m#+..        +
                        .-. m .. -.m++m####%###-##%.++*%++ m .
                      . +. m-- *##*#+###..-m+m.++.#-####-%-m.  ..
                      -m#--%###-m+- --+%m..--. -  .-*%####% ..-. -.
                   -...-*##%m+.+-+.++-m#+-. .. . +.+%%-#m..m#%m+..-.
                   -..*#**m.-.+..-.m+-##+.-       +m-+*%- %-- %##-
                 ...++*++.. . .     +m##*-.       -.%m+ +  -.-++%+-
                . ++###.%.--   . . *m+##%%.     .-%-#-    .  ...#...
                 ..%*+m       . + m+####%..     .-+%#+-       .-#--
                 -.#mm..    --.- +%#-m#%%     ...%+##%+        .+..\-
                .+mm%+ .. ..m-m.+%%+m**+..    --.##%m--.        + #-.
                .--%%.   . m .#++ %-- +mm-.  ...m##m-.+         -+*--
                 +-#+-   . .##+..   +..m     .m-#%#%--          -.##-.
               .%.**+. ...m#%..- .. ...# m . +-%#.%+           . %#%..+
               -+##%.+..  #-. -.       .m+..m -#%mm            .--**++
               .-%.*m+-...mm+        . .+ +-  -m-+.            ..*#.. .
               .-+*m#%m**++-+        ..  -##.%%.-            - ..##+-.
               - +-*%##%+mm--+          . .#m-m-           - -+.m.##-+.
                .. m*##*#*%-m+-  - .    . .m.+.m      ..     m%+.*-% -
                ...+##m%####m-+m- -.   .. ..- ++..  .  +.. +%-###m-%.
                 ..%#-%#++%####.+.m-+.     . +m#+#+%.. . -#*###m.--
                 . %-mm ++-mm+**##%mm.   - .+mm#+*.+--.#/##-+-+m    .
                ..+.#    - +-. m%m#m#*+.-..+##*###%m#%#% .--- - . .
                .-m#m. .  .  ..m+...#%m--+-*#+######.%+..  .+
              ..m-#%. .      ..- .+--  -   .---.-**-+--...
             .+.#m#m-            ..   . . - -..- ..*
            . +-##-+. .                     --  . ..
             .+##m%+
              .%.---
             ..  .
              ...

  http://en.wikipedia.org/wiki/Squatting
  https://github.com/beppu/squatting


The API (should fit comfortably in your head with plenty of room to spare).
---------------------------------------------------------------------------

## [0] BEGINNING AN APP

  package App;
  use Squatting;  # <-- This use statement is where the magic happens.
                  #
                  # %App::CONFIG
                  # &App::D
                  # &App::Controllers::R
                  # @App::Controllers::C
                  # %App::Controllers::C
                  # &App::Controllers::C
                  # &App::Views::R
                  # @App::Views::V
                  # %App::Views::V
                  #
                  # @App::ISA = qw(Squatting); 
                  #       # ...and Squatting->isa('Class::C3::Componentised')

## [1] CUSTOMIZING AN APP

  our %CONFIG = (
    # App configuration goes in a hash.
  );

  # Code that needs to run when the app starts goes in init().
  sub init {
    my ($class) = @_;
    $class->next::method();
  }

  # Code that needs to run on every request goes in service().
  sub service {
    my ($class, $controller, @args) = @_;
    
    # before controller

    my $content = $class->next::method($controller, @args);

    # after controller

    return $content;
  }

  1;

## [2] DEFINE CONTROLLERS

  package App::Controllers;
  our @C = (

    C(
      'Home' => [ '/' ],
      get => sub {
      }
    ),

    C(
      'Post' => [ '/(\d+)/(\d+)/(\w+)' ],
      get => sub {
        my ($self, $year, $month, $slug) = @_;
      },
      post => sub {
        my ($self, $year, $month, $slug) = @_;
      }
    )

    C(
      'Comment' => [ '/comment' ],
      post => sub {
      }
    )

  );

  1;

## [3] DEFINE VIEWS

  package App::Views;
  our @V = (
    V(
      'Default',

      layout => sub {
        my ($self, $v, $content) = @_;
        # This optional method allows you to wrap the content
        # that your template methods return.
        return "HEADER $content FOOTER";
      },

      _partial => sub {
        my ($self, $v) = @_;
        # If you want a view to not be wrapped by the layout,
        # its name should begin with "_".
        return "exactly what you want";
      },

      wrapped => sub {
        my ($self, $v) = @_;
        # This template's name does not begin with "_" so it
        # WILL be wrapped by the layout.
        return "wrapped content";
      }

      _ => sub {
        my ($self, $v) = @_;
        # If a named template method is not found, this method
        # will be run.  Think of it as AUTOLOAD for views.
        return "something";
      },

    ),
  );
                                    
  1;


SUMMARY OF THE SQUATTING API
----------------------------

%App::CONFIG            Where your app configuration is expected to be

&App::init              Code that runs on applicationn initialization

&App::service           Code that runs on every HTTP request

App::Controllers        Package where controllers are expected to be

@App::Controllers::C    Array where controllers are expected to be

&App::Controllers::C    Helper function for creating Squatting::Controller
                        objects

&App::Controllers::R    Helper function for generating URL paths;
                        Think "R" for "route".

App::Views              Package where views are expected to be

@App::Views::V          Array where views are expected to be

&App::Views::V          Helper function for creating Squatting::View objects

&App::Views::R          Helper function for generating URL paths;
                        It's the exact same function as &App::Controllers::R.
                        &App::Controllers::R == &App::Views::R


You should be able to memorize this quite easily, and I hope you
never have to use a search engine to figure out how any of this works.
The entire API should fit comfortably inside your mind with plenty of
room to spare.


For more information: 
  `perldoc Squatting`
  `perldoc Squatting::Controller`
  `perldoc Squatting::View`


For practical examples, see:
  Rhetoric     (a simple blogging system)
  Pod::Server  (a POD browser)
  Stardust     (a COMET server)

Something went wrong with that request. Please try again.