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