Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Object::Tiny; tests pass

  • Loading branch information...
commit c097e9dec6d931c57619bfcf734a57c7e0822d35 1 parent 86c260b
Zbigniew Lukasiak authored
View
2  Makefile.PL
@@ -5,7 +5,7 @@ all_from 'lib/WebNano.pm';
author q{Zbigniew Łukasiak <zby@cpan.org>};
license 'perl';
-requires 'Class::XSAccessor';
+requires 'Object::Tiny';
requires 'Plack' => 0.9938;
requires 'Plack::Request';
requires 'Scalar::Util';
View
2  lib/WebNano.pm
@@ -8,7 +8,7 @@ use base 'WebNano::FindController';
our $VERSION = '0.001';
use Plack::Response;
use Scalar::Util qw(blessed);
-use Class::XSAccessor { accessors => [ 'renderer' ], constructor => 'new' };
+use Object::Tiny 'renderer';
use Try::Tiny;
sub psgi_callback {
View
7 lib/WebNano/Controller.pm
@@ -9,16 +9,13 @@ use URI::Escape 'uri_unescape';
use Plack::Request;
use File::Spec::Functions qw/catfile catdir/;
-use Class::XSAccessor {
- accessors => [ qw/ application env self_path self_url url_map _request / ],
- constructor => 'new'
-};
+use Object::Tiny qw/ application env self_path self_url url_map _request /;
sub request {
my $self = shift;
return $self->_request if defined $self->_request;
my $req = Plack::Request->new( $self->env );
- $self->_request( $req );
+ $self->{_request} = $req;
return $req;
}
View
1  lib/WebNano/FindController.pm
@@ -3,6 +3,7 @@ use warnings;
package WebNano::FindController;
use Try::Tiny;
+use Object::Tiny;
sub find_nested {
my( $self, $sub_path, $search_path ) = @_;
View
4 lib/WebNano/TTTRenderer.pm
@@ -3,7 +3,7 @@ use strict;
use warnings;
use Template::Tiny;
-use Class::XSAccessor { accessors => [ qw/ root _tt_tiny / ], constructor => 'new', };
+use Object::Tiny qw/ root _tt_tiny /;
use File::Spec;
@@ -50,7 +50,7 @@ sub render {
open my $fh, $template or die "Cannot read from $template: $!";
my $string = do { local $/; <$fh> };
if( !$self->_tt_tiny ){
- $self->_tt_tiny( Template::Tiny->new() );
+ $self->{_tt_tiny} = Template::Tiny->new();
}
$self->_tt_tiny->process( \$string, $params{vars}, $params{output} );
}
View
3  t/00.load.t
@@ -1,7 +1,8 @@
-use Test::More tests => 1;
+use Test::More tests => 2;
BEGIN {
use_ok( 'WebNano' );
+use_ok( 'WebNano::Controller' );
}
diag( "Testing WebNano $WebNano::VERSION" );
View
8 t/10.main.t
@@ -2,15 +2,21 @@ use Test::More;
use Plack::Test;
use HTTP::Request::Common;
use lib 't/lib';
-use MyApp;
use File::Copy;
use WebNano::TTTRenderer;
+use MyApp;
+use MyApp::Controller;
+
my $dt = WebNano::TTTRenderer->new( root => 't/data/templates' );
my $rendered;
$dt->render( template => 'dummy_template', vars => { some_var => 'some value' }, output => \$rendered );
ok( $rendered =~ /some_var: some value/, 'vars' );
ok( $rendered =~ /^Some text/, 'Slurping template file' );
+my $app = MyApp->new();
+ok( $app, 'App created' );
+my $c = MyApp::Controller->new();
+ok( $c, 'Controller creaed' );
test_psgi(
app => MyApp->new()->psgi_callback,
View
8 t/lib/MyApp.pm
@@ -3,18 +3,18 @@ use warnings;
package MyApp;
use base 'WebNano';
-use Class::XSAccessor { accessors => [ 'config' ], };
+use Object::Tiny 'config';
use Config::Any;
use WebNano::TTTRenderer;
sub new {
my $class = shift;
- my $self = $class->SUPER::new( @_ );
+ my $self = bless {}, $class ;
my $cfg = Config::Any->load_stems({ stems => [ $self->config_file ], use_ext => 1 });
my @values = values %{$cfg->[0]};
my $config = $values[0];
- $self->config( $config );
- $self->renderer( WebNano::TTTRenderer->new( %{ $config->{renderer} } ) );
+ $self->{config} = $config;
+ $self->{renderer} = WebNano::TTTRenderer->new( %{ $config->{renderer} } );
return $self;
}
View
5 t/lib/MyApp/Controller.pm
@@ -8,8 +8,9 @@ use base 'WebNano::Controller';
sub new {
my $class = shift;
- my $self = $class->SUPER::new( @_ );
- $self->url_map( { 'mapped url' => 'mapped_url' } );
+ my $self = $class->SUPER::new( @_,
+ url_map => { 'mapped url' => 'mapped_url' }
+ );
return $self;
}
View
3  t/lib/MyApp/Controller/NestedController.pm
@@ -6,8 +6,7 @@ use base 'WebNano::Controller';
sub new {
my $class = shift;
- my $self = $class->SUPER::new( @_ );
- $self->url_map( [ 'safe_method' ] );
+ my $self = $class->SUPER::new( @_, url_map => [ 'safe_method' ] );
return $self;
}
Please sign in to comment.
Something went wrong with that request. Please try again.