[Rt-commit] r2568 - in experiments/Bamboo: . ex/trivial/bin
ex/trivial/html ex/trivial/lib ex/trivial/lib/Bamboo
jesse at bestpractical.com
jesse at bestpractical.com
Sun Apr 3 07:00:32 EDT 2005
Author: jesse
Date: Sun Apr 3 07:00:32 2005
New Revision: 2568
Added:
experiments/Bamboo/ex/trivial/bin/
experiments/Bamboo/ex/trivial/bin/server
experiments/Bamboo/ex/trivial/lib/Bamboo/Controller.pm
Modified:
experiments/Bamboo/ (props changed)
experiments/Bamboo/ex/trivial/html/autohandler
experiments/Bamboo/ex/trivial/lib/Counter.pm
Log:
r11669 at hualien: jesse | 2005-04-03 18:41:50 +0800
* Refactoring our sample prototype application into libraries, with a standalone server
Added: experiments/Bamboo/ex/trivial/bin/server
==============================================================================
--- (empty file)
+++ experiments/Bamboo/ex/trivial/bin/server Sun Apr 3 07:00:32 2005
@@ -0,0 +1,15 @@
+
+my $s=Eagle::Server->new(13432);
+$s->run();
+
+package Eagle::Server;
+use base qw/HTTP::Server::Simple::Mason/;
+use File::Spec;
+use FindBin;
+use lib $FindBin::Bin."/../lib";
+
+sub mason_config {
+ return ( comp_root => "$FindBin::Bin/../html");
+}
+
+1;
Modified: experiments/Bamboo/ex/trivial/html/autohandler
==============================================================================
--- experiments/Bamboo/ex/trivial/html/autohandler (original)
+++ experiments/Bamboo/ex/trivial/html/autohandler Sun Apr 3 07:00:32 2005
@@ -1,55 +1,12 @@
-<%PERL>
-# Controller
-Controller->run( $m->fetch_next->attr('Operations') );
-Controller->run( Controller->extract(\%ARGS) );
+<%init>
+use Bamboo::Controller;
+use Counter;
-....
-$m->notes( x => 1 );
-$m->subexec("/another_url.html", %some_other_args);
-$m->notes( 'x' );
-....
-
-$m->call_next; $m->abort;
-</%PERL>
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-<%INIT>
# Model
-{
package Bamboo;
our $VERSION = '0.01';
- package View;
+ package Bamboo::View;
sub new {
my $class = shift;
@@ -72,76 +29,14 @@
join('-' => 'Bamboo', Bamboo->VERSION, $::seq, "call", $self->class, $self->label, $meth);
}
- package Controller;
-
- sub extract {
- my ($self, $args) = @_;
-
- my $ws = qr/[^-]+/;
- my @ops;
-
- foreach my $key (sort keys %$args) {
- $key =~ /^Bamboo-$Bamboo::VERSION-\d+-(.+?)-($ws)-($ws)-($ws)/ or next;
- my ($op, $class, $label, $arg) = ($1, $2, $3, $4);
- push @ops, "$op $label $arg";
- }
-
- return \@ops;
- }
-
- sub run {
- my ($self, $ops) = @_;
- foreach my $op (@$ops) {
- if ($op =~ /new (\S+) (\S+)/) {
- my ($class, $label) = ($1, $2);
- $::c->{$label} = View->new(
- it => $class->new,
- label => $label,
- );
- }
- elsif ($op =~ /call (\S+) (\S+)/) {
- my ($label, $meth) = ($1, $2);
- $::c->{$label}->it->$meth;
- }
- }
- }
- package Counter;
+# Bamboo::Controller
+Bamboo::Controller->run( $m->fetch_next->attr('Operations') );
+Bamboo::Controller->run( Bamboo::Controller->extract(\%ARGS) );
- # Object
- # :attributes
- # - GET
- # - PUT
- # - DELETE
- # :methods
- # - call
- # - RC (result code)
-
- use YAML;
- use HTTP::Status;
- use fields qw( value );
-
- sub new {
- my $self = fields::new(shift);
-
- $self->{value} = eval {
- YAML::LoadFile('/tmp/counter.cnt')
- } || 0;
-
- return $self;
- }
-
- sub increment {
- my $self = shift;
- YAML::DumpFile('/tmp/counter.cnt' => (++$self->{value}));
- return RC_OK;
- }
-
- sub reset {
- my $self = shift;
- YAML::DumpFile('/tmp/counter.cnt' => ($self->{value} = 0));
- return RC_OK;
- }
-}
+$m->notes( x => 1 );
+$m->subexec("/another_url.html", %some_other_args);
+$m->notes( 'x' );
+$m->call_next; $m->abort;
</%INIT>
Added: experiments/Bamboo/ex/trivial/lib/Bamboo/Controller.pm
==============================================================================
--- (empty file)
+++ experiments/Bamboo/ex/trivial/lib/Bamboo/Controller.pm Sun Apr 3 07:00:32 2005
@@ -0,0 +1,34 @@
+ package Bamboo::Controller;
+
+ sub extract {
+ my ($self, $args) = @_;
+
+ my $ws = qr/[^-]+/;
+ my @ops;
+
+ foreach my $key (sort keys %$args) {
+ $key =~ /^Bamboo-$Bamboo::VERSION-\d+-(.+?)-($ws)-($ws)-($ws)/ or next;
+ my ($op, $class, $label, $arg) = ($1, $2, $3, $4);
+ push @ops, "$op $label $arg";
+ }
+
+ return \@ops;
+ }
+
+ sub run {
+ my ($self, $ops) = @_;
+ foreach my $op (@$ops) {
+ if ($op =~ /new (\S+) (\S+)/) {
+ my ($class, $label) = ($1, $2);
+ $::c->{$label} = Bamboo::View->new(
+ it => $class->new,
+ label => $label,
+ );
+ }
+ elsif ($op =~ /call (\S+) (\S+)/) {
+ my ($label, $meth) = ($1, $2);
+ $::c->{$label}->it->$meth;
+ }
+ }
+ }
+1;
Modified: experiments/Bamboo/ex/trivial/lib/Counter.pm
==============================================================================
--- experiments/Bamboo/ex/trivial/lib/Counter.pm (original)
+++ experiments/Bamboo/ex/trivial/lib/Counter.pm Sun Apr 3 07:00:32 2005
@@ -1,39 +1,41 @@
-package Counter;
+ use warnings;
+ use strict;
-use strict;
-use warnings;
-use YAML;
-
-
-package Counter;
-
-sub new {
- my $self = {};
- bless $self;
- my $cnt;
- eval {$cnt = YAML::LoadFile('/tmp/counter.cnt')};
- $self->set($cnt||0);
- return($self);
-
-}
-
-sub increment {
- my $self = shift;
- $self->set($self->value + 1);
-
-}
-
-sub value {
- my $self = shift;
- return $self->{counter};
-}
-
-sub set {
- my $self = shift;
- my $new = shift;
- $self->{'counter'} = $new;
- YAML::DumpFile('/tmp/counter.cnt', $self->{'counter'}) || die $@;
-}
+ package Counter;
+ # Object
+ # :attributes
+ # - GET
+ # - PUT
+ # - DELETE
+ # :methods
+ # - call
+ # - RC (result code)
+
+ use YAML;
+ use HTTP::Status;
+ use fields qw( value );
+
+ sub new {
+ my $self = fields::new(shift);
+
+ $self->{value} = eval {
+ YAML::LoadFile('/tmp/counter.cnt')
+ } || 0;
+
+ return $self;
+ }
+
+ sub increment {
+ my $self = shift;
+ YAML::DumpFile('/tmp/counter.cnt' => (++$self->{value}));
+ return RC_OK;
+ }
+
+ sub reset {
+ my $self = shift;
+ YAML::DumpFile('/tmp/counter.cnt' => ($self->{value} = 0));
+ return RC_OK;
+ }
1;
More information about the Rt-commit
mailing list