Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
initial
- Loading branch information
jamhed.nb
committed
Jan 26, 2012
0 parents
commit 78a0ba1
Showing
9 changed files
with
151 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
logs | ||
sessions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/usr/bin/env perl | ||
|
||
use lib qw( ./lib ); | ||
use Dancer; | ||
|
||
load_app 'Sample'; | ||
|
||
dance; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
logger: "file" | ||
log: "debug" | ||
logger_format: "%t %h %m" | ||
show_errors: 1 | ||
|
||
appname: "dancer-oo" | ||
appdir: './' | ||
session: "YAML" | ||
session_dir: "sessions" | ||
session_expires: 2592000 | ||
charset: 'utf-8' | ||
|
||
template: "template_toolkit" | ||
engines: | ||
template_toolkit: | ||
encoding: 'utf8' | ||
start_tag: '[%' | ||
end_tag: '%]' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package Dancer::OO::Dancer; | ||
use strict; | ||
use Dancer (); | ||
use JSON; | ||
|
||
sub debug { | ||
Dancer::debug( join( ' ', map { ref $_ ? Dump($_) : $_ } map { $_ ? $_ : '_' } @_ ) ); | ||
} | ||
|
||
sub import { | ||
my ($self) = @_; | ||
my $class = caller; | ||
no strict 'refs'; | ||
*{"$class\::get"} = sub { | ||
push @{ ${"$class\::_handler"} }, [ 'get', @_ ]; | ||
}; | ||
*{"$class\::post"} = sub { | ||
push @{ ${"$class\::_handler"} }, [ 'post', @_ ]; | ||
}; | ||
*{"$class\::any"} = sub { | ||
push @{ ${"$class\::_handler"} }, [ 'any', @_ ]; | ||
}; | ||
*{"$class\::template"} = sub { | ||
my ( $self, $template, $args ) = @_; | ||
$args = {} unless $args; | ||
$args->{uri} = sub { join( '', ${"$self\::_prefix"}, $_[0] ) }; | ||
my $k = join( '/', ${"$self\::_prefix"}, 'pager' ); | ||
$args->{c} ||= Dancer::session($k) || {}; | ||
return Dancer::template( join( '/', ${"$self\::_prefix"}, $template ), $args ); | ||
}; | ||
*{"$class\::upload"} = \&Dancer::upload; | ||
*{"$class\::content_type"} = \&Dancer::content_type; | ||
*{"$class\::header"} = \&Dancer::header; | ||
*{"$class\::redirect"} = \&Dancer::redirect; | ||
*{"$class\::wrap"} = sub (&) { | ||
my ($handler) = @_; | ||
return sub { | ||
my ($self) = @_; | ||
return sub { | ||
my $k = join( '/', ${"$self\::_prefix"}, 'pager' ); | ||
my $p = Dancer::params; | ||
my $context = Dancer::session($k) || {}; | ||
my $pp; | ||
foreach my $k ( keys %$p ) { | ||
$pp->{ decode( 'utf8', $k ) } = $p->{$k}; # fucking dancer utf8 bug again? | ||
} | ||
my $ret = $handler->( $self, $context, $pp ); | ||
Dancer::session( $k, $context ); | ||
return $ret; | ||
} | ||
} | ||
}; | ||
|
||
*{"$class\::json"} = sub { JSON->new->utf8(0)->pretty(1)->encode(shift) }; | ||
*{"$class\::debug"} = \&debug; | ||
|
||
*{"$class\::params"} = \&Dancer::params; | ||
*{"$class\::session"} = \&Dancer::session; | ||
} | ||
|
||
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package Dancer::OO::Object; | ||
use strict; | ||
use Dancer::OO::Dancer qw( debug ); | ||
|
||
# this module actually installs deferred and properly stacked uri handlers | ||
|
||
sub _build_tree { | ||
my ($package) = @_; | ||
return unless $package; | ||
no strict 'refs'; | ||
return map { $_, _build_tree($_) } @{"$package\::ISA"}; | ||
} | ||
|
||
# delay declarations | ||
sub import { | ||
my ( $self, $prefix ) = @_; | ||
no strict 'refs'; | ||
${"$self\::_prefix"} = $prefix; | ||
my @tree = ($self, _build_tree($self)); | ||
my %seen; | ||
foreach my $isa (@tree) { | ||
foreach ( @{ ${"$isa\::_handler"} } ) { | ||
my $path = join( '', $_->[0], $prefix, $_->[1] ) || '/'; | ||
next if $seen{$path}; | ||
debug( 'for', $self, $_->[0], $prefix . $_->[1], 'in', $isa); | ||
$seen{$path} = 1; | ||
Dancer::get $prefix . $_->[1] => $_->[2]->($self) if $_->[0] eq 'get'; | ||
Dancer::post $prefix . $_->[1] => $_->[2]->($self) if $_->[0] eq 'post'; | ||
Dancer::any $prefix . $_->[1] => $_->[2]->($self) if $_->[0] eq 'any'; | ||
} | ||
} | ||
} | ||
|
||
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package Sample; | ||
use strict; | ||
|
||
use Sample::Root '/'; | ||
use Sample::Demo '/demo'; | ||
|
||
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package Sample::Base; | ||
use strict; | ||
use parent 'Dancer::OO::Object'; | ||
use Dancer::OO::Dancer; | ||
|
||
get '' => wrap { | ||
my ($self, $context, $params) = @_; | ||
return <<HTML; | ||
<html><body>Holla</body></html> | ||
HTML | ||
}; | ||
|
||
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package Sample::Demo; | ||
use parent 'Sample::Base'; | ||
|
||
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package Sample::Root; | ||
use parent 'Sample::Base'; | ||
|
||
1; |