From eb9a0d361b37c5b3a7d750385f6b3a3300301fbc Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Mon, 21 Feb 2011 00:26:12 -0600 Subject: test all inlining --- lib/MooseX/Bread/Board.pm | 1 + lib/MooseX/Bread/Board/Meta/Role/Attribute.pm | 4 +- lib/MooseX/Bread/Board/Meta/Role/Instance.pm | 9 ++ t/10-inlining.t | 143 ++++++++++++++++++++++++++ 4 files changed, 155 insertions(+), 2 deletions(-) create mode 100644 lib/MooseX/Bread/Board/Meta/Role/Instance.pm create mode 100644 t/10-inlining.t diff --git a/lib/MooseX/Bread/Board.pm b/lib/MooseX/Bread/Board.pm index f40797e..fbf536b 100644 --- a/lib/MooseX/Bread/Board.pm +++ b/lib/MooseX/Bread/Board.pm @@ -6,6 +6,7 @@ my (undef, undef, $init_meta) = Moose::Exporter->build_import_methods( class_metaroles => { attribute => ['MooseX::Bread::Board::Meta::Role::Attribute'], class => ['MooseX::Bread::Board::Meta::Role::Class'], + instance => ['MooseX::Bread::Board::Meta::Role::Instance'], }, base_class_roles => ['MooseX::Bread::Board::Role::Object'], ); diff --git a/lib/MooseX/Bread/Board/Meta/Role/Attribute.pm b/lib/MooseX/Bread/Board/Meta/Role/Attribute.pm index 90a10e5..fe98bb7 100644 --- a/lib/MooseX/Bread/Board/Meta/Role/Attribute.pm +++ b/lib/MooseX/Bread/Board/Meta/Role/Attribute.pm @@ -99,9 +99,9 @@ around inline_get => sub { my $self = shift; my ($instance) = @_; - return '((' . $self->inline_has($instance) . ')' . "\n" + return 'do { (' . $self->inline_has($instance) . ')' . "\n" . '? (' . $self->$orig($instance) . ')' . "\n" - . ': (' . $instance . '->get_service(\'' . $self->name . '\')->get))'; + . ': (' . $instance . '->get_service(\'' . $self->name . '\')->get) }'; }; no Moose::Role; diff --git a/lib/MooseX/Bread/Board/Meta/Role/Instance.pm b/lib/MooseX/Bread/Board/Meta/Role/Instance.pm new file mode 100644 index 0000000..93648e2 --- /dev/null +++ b/lib/MooseX/Bread/Board/Meta/Role/Instance.pm @@ -0,0 +1,9 @@ +package MooseX::Bread::Board::Meta::Role::Instance; +use Moose::Role; + +# XXX: ugh, this should be settable at the attr level, fix this in moose +sub inline_get_is_lvalue { 0 } + +no Moose::Role; + +1; diff --git a/t/10-inlining.t b/t/10-inlining.t new file mode 100644 index 0000000..658d42d --- /dev/null +++ b/t/10-inlining.t @@ -0,0 +1,143 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use Test::More; + +{ + package Foo; + use Moose; + use MooseX::Bread::Board; + + has foo => ( + reader => 'get_foo', + writer => 'set_foo', + accessor => 'foo', + predicate => 'has_foo', + clearer => 'clear_foo', + value => 'foo', + ); + + has bool => ( + traits => ['Bool'], + isa => 'Bool', + default => 0, + handles => { + bool_unset => 'unset', + bool_set => 'set', + bool_not => 'not', + bool_toggle => 'toggle', + }, + ); + + has string => ( + traits => ['String'], + isa => 'Str', + default => '', + handles => { + string_prepend => 'prepend', + string_chop => 'chop', + string_substr => 'substr', + string_match => 'match', + string_length => 'length', + string_inc => 'inc', + string_append => 'append', + string_clear => 'clear', + string_chomp => 'chomp', + string_replace => 'replace', + }, + ); + + has hash => ( + traits => ['Hash'], + isa => 'HashRef', + default => sub { {} }, + handles => { + hash_delete => 'delete', + hash_exists => 'exists', + hash_values => 'values', + hash_get => 'get', + hash_set => 'set', + hash_is_empty => 'is_empty', + hash_keys => 'keys', + hash_elements => 'elements', + hash_kv => 'kv', + hash_defined => 'defined', + hash_accessor => 'accessor', + hash_count => 'count', + hash_clear => 'clear', + }, + ); + + has counter => ( + traits => ['Counter'], + isa => 'Int', + default => 1, + handles => { + counter_set => 'set', + counter_reset => 'reset', + counter_inc => 'inc', + counter_dec => 'dec', + }, + ); + + has code => ( + traits => ['Code'], + isa => 'CodeRef', + default => 1, + handles => { + code_execute => 'execute', + code_execute_method => 'execute_method', + }, + ); + + has array => ( + traits => ['Array'], + isa => 'ArrayRef', + default => sub { [] }, + handles => { + array_unshift => 'unshift', + array_shuffle => 'shuffle', + array_delete => 'delete', + array_get => 'get', + array_set => 'set', + array_uniq => 'uniq', + array_is_empty => 'is_empty', + array_shift => 'shift', + array_grep => 'grep', + array_sort_in_place => 'sort_in_place', + array_sort => 'sort', + array_elements => 'elements', + array_pop => 'pop', + array_reduce => 'reduce', + array_insert => 'insert', + array_join => 'join', + array_first => 'first', + array_natatime => 'natatime', + array_accessor => 'accessor', + array_count => 'count', + array_map => 'map', + array_push => 'push', + array_clear => 'clear', + array_splice => 'splice', + }, + ); + + has number => ( + traits => ['Number'], + isa => 'Num', + default => 1, + handles => { + number_add => 'add', + number_set => 'set', + number_sub => 'sub', + number_mul => 'mul', + number_mod => 'mod', + number_abs => 'abs', + number_div => 'div', + }, + ); +} + +pass("everything compiled successfully"); + +done_testing; -- cgit v1.2.3-54-g00ecf