• Stars
    star
    37
  • Rank 717,475 (Top 15 %)
  • Language
    Perl
  • License
    MIT License
  • Created over 16 years ago
  • Updated almost 9 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A Camping-inspired Web Microframework for Perl

                                                                  -+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)

More Repositories

1

jquery-ev

a COMET event loop for jQuery
JavaScript
43
star
2

stardust

the simplest COMET server I could imagine
JavaScript
24
star
3

anyevent-couchdb

a non-blocking CouchDB client for Perl based on jquery.couch.js
Perl
19
star
4

mad-scientists-lab

a place for collaborative hacking w/ fellow mad scientists
JavaScript
15
star
5

pod-server

a web server for locally installed perl documentation -- think gem_server for perl
Perl
10
star
6

squatting-on-http-engine

run Squatting apps on top of HTTP::Engine
Perl
9
star
7

webservice-mtgox

a perl library for mtgox.com's bitcoin trading API
Perl
6
star
8

Squatting-On-PSGI

Run Squatting apps on PSGI
Perl
5
star
9

linux-input

a Perl interface to Linux's input event system
Perl
4
star
10

rhetoric

a simple blogging system for perl
Perl
4
star
11

app-vw

a deployment system for Squatting+Continuity apps
Perl
4
star
12

metanotes

...
JavaScript
3
star
13

learning

Everything I know about X, I learned from Y. (a simple Camping app)
Ruby
3
star
14

bavl

The Towering Inferno of Bavl
3
star
15

beppu.github.io

Beppu's GitHub Pages
HTML
3
star
16

timer

A GUI App For Managing Multiple Timers Written In Clojure
Clojure
2
star
17

angelfoodsgv

a school lunch ordering system for st. angela merici school in brea, ca
PHP
2
star
18

squatting-on-mojo

run Squatting apps on top of Mojo
Perl
2
star
19

rhetoric-theme-jquerymobile

a mobile theme for Rhetoric blogs
JavaScript
2
star
20

blog

source for beppu.github.io
CSS
1
star
21

nomad-summit-2017-notes

My notes from Nomad Summit 2017 in Chiang Mai, Thailand
1
star
22

rhetoric-theme-sandstone

a Rhetoric theme based on SandStone from Free CSS Templates
CSS
1
star