Changes for avoiding inline_slot_access
[gitmo/Moose.git] / t / 020_attributes / 028_no_slot_access.t
CommitLineData
e3441425 1#!/usr/bin/perl
2
3package SomeAwesomeDB;
4
5sub new_row { }
6sub read { }
7sub write { }
8
9package MooseX::SomeAwesomeDBFields;
10
11use Moose::Role;
12
13sub inline_create_instance {
14 my ($self, $classvar) = @_;
15
16 "bless SomeAwesomeDB::new_row(), $classvar";
17}
18
19sub inline_get_slot_value {
20 my ($self, $invar, $slot) = @_;
21
22 "SomeAwesomeDB::read($invar, \"$slot\")";
23}
24
25sub inline_set_slot_value {
26 my ($self, $invar, $slot, $valexp) = @_;
27
28 "SomeAwesomeDB::write($invar, \"$slot\", $valexp)";
29}
30
31sub inline_is_slot_initialized {
32 my ($self, $invar, $slot) = @_;
33
34 "1";
35}
36
37sub inline_initialize_slot {
38 my ($self, $invar, $slot) = @_;
39
40 "";
41}
42
43sub inline_slot_access {
44 die "inline_slot_access should not have been used";
45}
46
47# implementation of methods not called in the example deliberately
48# omitted
49
50package Toy;
51
52use Moose;
53use Moose::Util::MetaRole;
54
55use Test::More tests => 3;
56use Test::Exception;
57
58Moose::Util::MetaRole::apply_metaclass_roles
59 (for_class => __PACKAGE__,
60 instance_metaclass_roles => [ 'MooseX::SomeAwesomeDBFields' ]);
61
62lives_ok {
63 has lazy_attr => (
64 is => 'ro',
65 isa => 'Bool',
66 lazy => 1,
67 default => sub { 0 },
68 );
69} "Adding lazy accessor does not use inline_slot_access";
70
71lives_ok {
72 has rw_attr => (
73 is => 'rw',
74 );
75} "Adding read-write accessor does not use inline_slot_access";
76
77lives_ok { __PACKAGE__->meta->make_immutable; }
78 "Inling constructor does not use inline_slot_access";