Permalink
Browse files

Config methods were moved to Schenker::Options

  • Loading branch information...
1 parent f584f98 commit d047b32b46d4fc9d1e76288b192b26dbc26973eb @spiritloose committed Aug 4, 2009
Showing with 45 additions and 35 deletions.
  1. +1 −34 lib/Schenker.pm
  2. +44 −1 lib/Schenker/Options.pm
View
@@ -25,7 +25,6 @@ our $Engine;
our $Initialized;
our $Exited;
our $Middleware;
-our $Options;
our @Filters;
our %Errors;
our %Templates;
@@ -34,13 +33,11 @@ our %TTOptions;
our @EXPORT = (qw/
get head post put Delete
- options set enable disable configure
- development test production
Use helpers Before error not_found define_error
request response stash session status param params redirect halt
back body content_type etag headers last_modified
media_type mime attachment send_file
-/, @Schenker::Templates::EXPORT);
+/, @Schenker::Options::EXPORT, @Schenker::Templates::EXPORT);
sub import {
croak q/Can't use Schenker twice./ if defined $App;
@@ -64,8 +61,6 @@ sub unimport {
}
}
-sub options { $Options ||= Schenker::Options->new }
-
sub middleware {
$Middleware ||= HTTP::Engine::Middleware->new(
method_class => 'HTTP::Engine::Request',
@@ -174,34 +169,6 @@ sub Delete { route 'DELETE', @_ }
sub put { route 'PUT', @_ }
-sub set {
- croak 'usage: set $option => $value' if @_ % 2 != 0;
- options->set(@_);
-}
-
-sub enable {
- my $option = shift or croak 'option required';
- set $option => 1;
-}
-
-sub disable {
- my $option = shift or croak 'option required';
- set $option => 0;
-}
-
-sub development { options->environment eq 'development' }
-
-sub test { options->environment eq 'test' }
-
-sub production { options->environment eq 'production' }
-
-sub configure {
- my $code = pop or croak 'code required';
- croak 'code must be coderef' if ref $code ne 'CODE';
- my @envs = @_;
- $code->() if @envs == 0 or any { $_ eq options->environment } @envs;
-}
-
sub helpers {
croak 'usage: helpers $name => $code' if @_ % 2 != 0;
my %helpers = @_;
View
@@ -1,12 +1,55 @@
package Schenker::Options;
use Any::Moose;
+use base 'Exporter';
+
+use Carp qw(croak);
+use List::MoreUtils qw(any);
+
+our @EXPORT = qw(
+ configure options set enable disable
+ development test production
+);
+
+my $instance;
+
+sub options {
+ $instance ||= __PACKAGE__->new;
+}
sub set {
+ croak 'usage: set $option => $value' if @_ % 2 != 0;
+ options->define(@_);
+}
+
+sub enable {
+ my $option = shift or croak 'option required';
+ set $option => 1;
+}
+
+sub disable {
+ my $option = shift or croak 'option required';
+ set $option => 0;
+}
+
+sub development { options->environment eq 'development' }
+
+sub test { options->environment eq 'test' }
+
+sub production { options->environment eq 'production' }
+
+sub configure {
+ my $code = pop or croak 'code required';
+ croak 'code must be coderef' if ref $code ne 'CODE';
+ my @envs = @_;
+ $code->() if @envs == 0 or any { $_ eq options->environment } @envs;
+}
+
+sub define {
my $self = shift;
my %options = @_;
while (my ($option, $value) = each %options) {
unless (ref $value eq 'CODE') {
- return $self->set($option => sub { $value });
+ return $self->define($option => sub { $value });
} else {
$self->meta->add_method($option => sub { $value->() });
}

0 comments on commit d047b32

Please sign in to comment.