On Wed, Apr 11, 2012 at 10:04 AM, Karen Etheridge <ka...@etheridge.ca> wrote:
>    has attr => (
>    is => 'rw',
>    isa => 'Str',
>    init_arg => 'attribute',
>    accessor => 'attribute',
> );
>
> so these tests will hold true:
>
> isnt(exception { Class->new(attr=>'foo') }, undef,
>    'cannot construct with the "attr" name');

Class->new(attr => 'foo') should not throw an exception

oh I hate the Test::Fatal syntax,  using the original name should
work, the additional init arg needs to be an alternate. I wonder if
RJBS would add just a dies { } that wraps exception is ( dies { },
'exception string', 'dies with correct exception' )  (because every
time I see `is exception { ...` I read this is an exception even if
the 2nd arg is undef ) I don't mind the more flexible syntax, I just
think the naming makes it unreadable. I tried the lives_ok/dies_ok in
Test::Fatal but they completely obscured the exception error.

> my $obj;
> is(exception { $obj = Class->new(attribute => 'foo') }, undef,
>    'can construct with the "attribute" name');

Class->new( attribute => 'foo' ) should not throw an exception

> ok(exists($obj->{attr}, 'the "attr" slot is used for storage');

this seems dirty, I don't really care internally how the object is
storing it (well I do but this is gut poking)

> is(exception { $obj->attribute('bar') }, undef,
>    'can alter the value with the "attribute" accessor');

no attribute accessor would be available, attribute is the other name.

> ok(!$obj->can('attr'), 'no attr method exists');
>
an attr accessor would be available

> If I am wrong, please correct these tests to demonstrate the desired
> behaviour.

basically all but one of your tests would fail I think, have I
actually explained alternate constructor only so poorly? if so I would
love to understand how I could have explained better.

aliases doesn't work for one big reason. This thing I'm writing is
also providing me with "metadata" in that having it applied to the
attribute makes the attribute special beyond added functionality. If I
or someone else decided to use Aliases later, even if it was otherwise
a completely workable solution, then the added aliases would break the
use of this metadata, by adding invalid metadata.

Aliases allowing multiple aliases and banning the same name does not
work for me because alternate name is actually a remote name not an
alternate, and sometimes I want to use the same name with the
metadata, but that had nothing to do with the road block I was
hitting, which is my ignorance on ::Exporter and Moose extensions so I
tried to leave all that out.

-- 
Caleb Cushing

http://xenoterracide.com

Reply via email to