merge trunk to pluggable errors
[gitmo/Moose.git] / t / 000_recipes / extending / 002_metaclass_and_sugar.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More tests => 3;
7
8
9 {
10     package MyApp::Meta::Class;
11     use Moose;
12
13     extends 'Moose::Meta::Class';
14
15     has 'table' => ( is => 'rw' );
16
17     no Moose;
18
19     package MyApp::Mooseish;
20
21     use strict;
22     use warnings;
23
24     use Moose ();
25     use Moose::Exporter;
26
27     Moose::Exporter->setup_import_methods(
28         with_caller => ['has_table'],
29         also        => 'Moose',
30     );
31
32     sub init_meta {
33         shift;
34         Moose->init_meta( @_, metaclass => 'MyApp::Meta::Class' );
35     }
36
37     sub has_table {
38         my $caller = shift;
39         $caller->meta()->table(shift);
40     }
41 }
42
43 {
44     package MyApp::User;
45
46     MyApp::Mooseish->import;
47
48     has_table( 'User' );
49
50     has( 'username' => ( is => 'ro' ) );
51     has( 'password' => ( is => 'ro' ) );
52
53     sub login { }
54 }
55
56 isa_ok( MyApp::User->meta, 'MyApp::Meta::Class' );
57 is( MyApp::User->meta->table, 'User',
58     'MyApp::User->meta->table returns User' );
59 ok( MyApp::User->can('username'),
60     'MyApp::User has username method' );