Permalink
Browse files

Merge branch 'sawyer_goes_to_yapc'

  • Loading branch information...
2 parents 09f1643 + c2ec612 commit 92e9e4f5f9e626a6595ce2eaaa53edb9529f13d5 @xsawyerx xsawyerx committed Aug 23, 2012
View
@@ -10,4 +10,3 @@ MYMETA.yml
contrib/sessions/
contrib/logs/
*.sw?
-Dancer*
@@ -6,7 +6,11 @@ use Dancer::Moo::Types;
with 'Dancer::Core::Role::Hookable';
-requires 'type';
+has type => (
+ is => 'ro',
+ lazy => 1,
+ builder => 1,
+);
has environment => (is => 'ro');
has location => (is => 'ro');
@@ -22,4 +26,6 @@ has config => (
default => sub { {} },
);
+requires '_build_type';
+
1;
@@ -14,13 +14,13 @@ sub supported_hooks {
)
}
-sub type { 'Logger' }
+sub _build_type {'Logger'}
# This is the only method to implement by logger engines.
# It receives the following arguments:
# $msg_level, $msg_content, it gets called only if the configuration allows
# a message of the given level to be logged.
-requires '_log';
+requires 'log';
has auto_encoding_charset => (
is => 'ro',
@@ -118,9 +118,9 @@ sub format_message {
return $fmt."\n";
}
-sub core { $_[0]->_should('core') and $_[0]->_log('core', $_[1]) }
-sub debug { $_[0]->_should('debug') and $_[0]->_log('debug', $_[1]) }
-sub warning { $_[0]->_should('warning') and $_[0]->_log('warning', $_[1]) }
-sub error { $_[0]->_should('error') and $_[0]->_log('error', $_[1]) }
+sub core { $_[0]->_should('core') and $_[0]->log('core', $_[1]) }
+sub debug { $_[0]->_should('debug') and $_[0]->log('debug', $_[1]) }
+sub warning { $_[0]->_should('warning') and $_[0]->log('warning', $_[1]) }
+sub error { $_[0]->_should('error') and $_[0]->log('error', $_[1]) }
1;
@@ -13,7 +13,7 @@ sub supported_hooks {
)
}
-sub type { 'Serializer' }
+sub _build_type {'Serializer'}
requires 'serialize';
requires 'deserialize';
@@ -17,7 +17,7 @@ use Dancer::Core::Context;
has name => (
is => 'ro',
lazy => 1,
- builder => '_build_name',
+ builder => 1,
);
has host => (
@@ -8,7 +8,7 @@ use File::Spec;
use Moo::Role;
with 'Dancer::Core::Role::Engine';
-sub type { 'Session' }
+sub _build_type {'Session'}
sub supported_hooks { }
@@ -19,10 +19,17 @@ sub supported_hooks {
/
}
-sub type { 'Template' }
+sub _build_type {'Template'}
+requires '_build_name';
requires 'render';
+has name => (
+ is => 'ro',
+ lazy => 1,
+ builder => 1,
+);
+
has charset => (
is => 'ro',
isa => Str,
@@ -7,7 +7,7 @@ use Plack::Request;
with 'Dancer::Core::Role::Server';
-sub _build_name { 'PSGI' }
+has _build_name {'PSGI'}
sub start {
my ($self) = @_;
@@ -5,7 +5,7 @@ package Dancer::Core::Server::Standalone;
use Moo;
with 'Dancer::Core::Role::Server';
-sub _build_name { 'Standalone' }
+sub _build_name {'Standalone'}
use HTTP::Server::Simple::PSGI;
@@ -6,13 +6,18 @@ use Dancer::Logger::Capture::Trap;
with 'Dancer::Core::Role::Logger';
-my $_trap = Dancer::Logger::Capture::Trap->new;
-sub trap { $_trap }
+has trapper => (
+ is => 'ro',
+ lazy => 1,
+ builder => '_build_trapper',
+);
-sub _log {
+sub _build_trapper { Dancer::Logger::Capture::Trap->new }
+
+sub log {
my($self, $level, $message) = @_;
- $_trap->store( $level => $message );
+ $self->trapper->store( $level => $message );
return;
}
@@ -4,22 +4,22 @@ package Dancer::Logger::Capture::Trap;
use Moo;
use Dancer::Moo::Types;
-has _storage => (
+has storage => (
is => 'rw',
isa => ArrayRef,
default => sub { [] },
);
sub store {
my($self, $level, $message) = @_;
- push @{$self->_storage}, { level => $level, message => $message };
+ push @{$self->storage}, { level => $level, message => $message };
}
sub read {
my $self = shift;
- my $logs = $self->_storage;
- $self->_storage([]);
+ my $logs = $self->storage;
+ $self->storage([]);
return $logs;
}
@@ -4,7 +4,7 @@ package Dancer::Logger::Console;
use Moo;
with 'Dancer::Core::Role::Logger';
-sub _log {
+sub log {
my ($self, $level, $message) = @_;
print STDERR $self->format_message($level => $message);
}
@@ -5,7 +5,7 @@ use Moo;
use Test::More;
with 'Dancer::Core::Role::Logger';
-sub _log {
+sub log {
my ($self, $level, $message) = @_;
Test::More::diag(
@@ -61,7 +61,7 @@ sub BUILD {
$self->fh($fh);
}
-sub _log {
+sub log {
my ($self, $level, $message) = @_;
my $fh = $self->fh;
@@ -5,7 +5,7 @@ use Moo;
use Test::More;
with 'Dancer::Core::Role::Logger';
-sub _log {
+sub log {
my ($self, $level, $message) = @_;
Test::More::note(
@@ -4,7 +4,7 @@ package Dancer::Logger::Null;
use Moo;
with 'Dancer::Core::Role::Logger';
-sub _log {1}
+sub log {1}
1;
@@ -22,7 +22,7 @@ sub to_yaml {
# class definition
sub BUILD { eval "use YAML::Any ()"; croak "Fail to load YAML: $@" if $@ }
-sub loaded { 1 }
+sub loaded {1}
sub serialize {
my ($self, $entity) = @_;
@@ -16,6 +16,8 @@ has engine => (
isa => ObjectOf('Template'),
);
+sub _build_name {'TemplateToolkit'}
+
sub BUILD {
my ($self) = @_;
@@ -12,11 +12,13 @@ use Dancer::FileUtils 'read_file_content';
with 'Dancer::Core::Role::Template';
has engine => (
- is => 'rw',
+ is => 'rw',
+ isa => ObjectOf('Template::Tiny'),
default => sub { Template::Tiny->new },
- isa => ObjectOf('Template::Tiny'),
);
+sub _build_name {'Tiny'}
+
sub render {
my ( $self, $template, $tokens ) = @_;
View
@@ -1,22 +1,7 @@
-use Test::More;
use strict;
use warnings;
-
-{
- package Dancer::Core::Role::Template;
- use Moo::Role;
- with 'Dancer::Core::Role::Engine';
- requires 'render';
-
- package Dancer::Template::Tiny;
- use Moo;
- with 'Dancer::Core::Role::Template';
-
- sub name { 'Tiny' }
- sub type { 'Template' }
- sub render { "tiny" }
- sub supported_hooks { }
-}
+use Test::More;
+use Dancer::Template::Tiny;
my $f = Dancer::Template::Tiny->new();
isa_ok $f, 'Dancer::Template::Tiny';
View
@@ -14,7 +14,7 @@ my $_logs = [];
use Moo;
with 'Dancer::Core::Role::Logger';
- sub _log {
+ sub log {
my ($self, $level, $message) = @_;
push @$_logs, $self->format_message($level, $message);
}
@@ -35,7 +35,8 @@ subtest 'logger capture' => sub {
warning "Danger! Warning!";
debug "I like pie.";
- my $trap = Dancer::Logger::Capture->trap;
+ my $app = dancer_app;
+ my $trap = $app->setting('logger')->trapper;
is_deeply $trap->read, [
{ level => "warning", message => "Danger! Warning!" },
{ level => "debug", message => "I like pie.", }
View
@@ -9,7 +9,7 @@ use warnings;
use Moo;
with 'Dancer::Core::Role::Server';
- sub _build_name { "foo" }
+ sub _build_name {'foo'}
}
my $s;

0 comments on commit 92e9e4f

Please sign in to comment.