File Coverage

blib/lib/Poet/t/Subclassing.pm
Criterion Covered Total %
statement 1 3 33.3
branch n/a
condition n/a
subroutine 1 1 100.0
pod n/a
total 2 4 50.0


line stmt bran cond sub pod time code
1             package Poet::t::Subclassing;
2             $Poet::t::Subclassing::VERSION = '0.16';
3 1     1   1105 use Poet::Tools qw(write_file);
  0            
  0            
4             use Test::Class::Most parent => 'Poet::Test::Class';
5              
6             sub test_subclassing : Tests {
7             my $self = shift;
8              
9             my $root_dir = $self->temp_env_dir();
10             write_file( "$root_dir/lib/TestApp/Cache.pm",
11             join( "\n", "package TestApp::Cache;", "use Poet::Moose;", "extends 'Poet::Cache';" ) );
12             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             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             my $poet = Poet::Environment->initialize_current_environment(
33             root_dir => $root_dir,
34             app_name => 'TestApp'
35             );
36             isa_ok( $poet, 'Poet::Environment', 'env' ); # can't override this yet
37             isa_ok( $poet->importer, 'TestApp::Import', 'import' );
38             isa_ok( $poet->conf, 'TestApp::Conf', 'conf' );
39             is( $poet->app_class('Cache'), 'TestApp::Cache', 'cache' );
40              
41             {
42             package Foo;
43             $Foo::VERSION = '0.16';
44             Poet->import(qw($cache $conf $log $poet));
45             use Test::More;
46             is( $Foo::cache->chi_root_class, 'TestApp::Cache', '$cache' );
47             isa_ok( $Foo::conf, 'TestApp::Conf', '$conf' );
48             isa_ok( $Foo::log, 'TestApp::Logger', '$log' );
49             isa_ok( $Foo::poet, 'Poet::Environment', '$poet' );
50             is( Foo::bar(), 5, 'imported bar' );
51             }
52             }
53              
54             1;