Requires Test::Warn 0.11 to avoid some bugs it seems to trigger (based on a report...
[gitmo/Moose.git] / t / 000_recipes / extending / 001_base_class.t
CommitLineData
554b7648 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
6use Test::More;
7use Test::Exception;
8
9BEGIN {
e5efd577 10 unless ( eval 'use Test::Warn 0.11; 1' ) {
11 plan skip_all => 'These tests require Test::Warn 0.11+';
554b7648 12 }
13 else {
14 plan tests => 4;
15 }
16}
17
18{
19 package MyApp::Base;
20 use Moose;
21
22 extends 'Moose::Object';
23
24 before 'new' => sub { warn "Making a new " . $_[0] };
25
26 no Moose;
27}
28
29{
30 package MyApp::UseMyBase;
31 use Moose ();
32 use Moose::Exporter;
33
aedcb7d9 34 Moose::Exporter->setup_import_methods( also => 'Moose' );
554b7648 35
36 sub init_meta {
37 shift;
38 Moose->init_meta( @_, base_class => 'MyApp::Base' );
39 }
40}
41
42{
43 package Foo;
44
45 MyApp::UseMyBase->import;
46
47 has( 'size' => ( is => 'rw' ) );
48}
49
50ok( Foo->isa('MyApp::Base'),
51 'Foo isa MyApp::Base' );
52
53ok( Foo->can('size'),
54 'Foo has a size method' );
55
56my $foo;
57warning_is( sub { $foo = Foo->new( size => 2 ) },
58 'Making a new Foo',
59 'got expected warning when calling Foo->new' );
60
61is( $foo->size(), 2, '$foo->size is 2' );
62