| 1 | package Poet::t::Subclassing; | ||
| 2 | 1 | $Poet::t::Subclassing::VERSION = '0.16'; | |
| 3 | 1 | ▶ | use Poet::Tools qw(write_file); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 1 | ▶ | use Test::Class::Most parent => 'Poet::Test::Class'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | |||
| 6 | 1 | ▶ | sub test_subclassing : Tests { |
|
Subroutine
test_subclassing: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 7 | 1 | my $self = shift; | |
| 8 | |||
| 9 | 1 | my $root_dir = $self->temp_env_dir(); | |
| 10 | 1 | write_file( "$root_dir/lib/TestApp/Cache.pm", | |
| 11 | join( "\n", "package TestApp::Cache;", "use Poet::Moose;", "extends 'Poet::Cache';" ) ); | ||
| 12 | 1 | write_file( | |
| 13 | "$root_dir/lib/TestApp/Import.pm", | ||
| 14 | join( "\n", | ||
| 15 | "package TestApp::Import;", | ||
| 16 | "use Poet::Moose;", | ||
| 17 | "extends 'Poet::Import';", | ||
| 18 | "no strict 'refs';", | ||
| 19 | "before 'export_to_class' => sub { *{\$_[1] . '::bar'} = sub { 5 } };", | ||
| 20 | "1", | ||
| 21 | ) | ||
| 22 | ); | ||
| 23 | 1 | write_file( | |
| 24 | "$root_dir/lib/TestApp/Log.pm", | ||
| 25 | join( "\n", | ||
| 26 | "package TestApp::Log;", | ||
| 27 | "use Poet::Moose;", | ||
| 28 | "extends 'Poet::Log';", | ||
| 29 | "sub get_logger { return bless({}, 'TestApp::Logger') }", | ||
| 30 | ) | ||
| 31 | ); | ||
| 32 | 1 | my $poet = Poet::Environment->initialize_current_environment( | |
| 33 | root_dir => $root_dir, | ||
| 34 | app_name => 'TestApp' | ||
| 35 | ); | ||
| 36 | 1 | isa_ok( $poet, 'Poet::Environment', 'env' ); # can't override this yet | |
| 37 | 1 | isa_ok( $poet->importer, 'TestApp::Import', 'import' ); | |
| 38 | 1 | isa_ok( $poet->conf, 'TestApp::Conf', 'conf' ); | |
| 39 | 1 | is( $poet->app_class('Cache'), 'TestApp::Cache', 'cache' ); | |
| 40 | |||
| 41 | { | ||
| 42 | 1 | package Foo; | |
| 43 | 1 | $Foo::VERSION = '0.16'; | |
| 44 | 1 | Poet->import(qw($cache $conf $log $poet)); | |
| 45 | 1 | ▶ | use Test::More; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 46 | 1 | is( $Foo::cache->chi_root_class, 'TestApp::Cache', '$cache' ); | |
| 47 | 1 | isa_ok( $Foo::conf, 'TestApp::Conf', '$conf' ); | |
| 48 | 1 | isa_ok( $Foo::log, 'TestApp::Logger', '$log' ); | |
| 49 | 1 | isa_ok( $Foo::poet, 'Poet::Environment', '$poet' ); | |
| 50 | 1 | is( Foo::bar(), 5, 'imported bar' ); | |
| 51 | } | ||
| 52 | 1 | ▶ | } |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 53 | |||
| 54 | 1 | 1; | |