CC: | Evan Carroll <me [...] evancarroll.com> |
Subject: | [PATCH] added new test |
Date: | Thu, 23 Apr 2009 17:54:12 -0500 |
To: | bug-MooseX-ClassAttribute [...] rt.cpan.org |
From: | Evan Carroll <me [...] evancarroll.com> |
---
t/05-with-initializer.t | 86 +++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 86 insertions(+), 0 deletions(-)
create mode 100644 t/05-with-initializer.t
diff --git a/t/05-with-initializer.t b/t/05-with-initializer.t
new file mode 100644
index 0000000..343524f
--- /dev/null
+++ b/t/05-with-initializer.t
@@ -0,0 +1,86 @@
+#!/usr/bin/env perl
+
+## COPYRIGHT EVAN CARROLL me+cpan < @T > evancarroll <dot> com
+## FOR SUPPORT ON THIS TEST VISIT irc.freenode.net/#perlcafe
+package ClassFoo;
+use Moose;
+use MooseX::ClassAttribute;
+
+class_has 'chas' => (
+ isa => 'Str'
+ , is => 'ro'
+ , default => 'Foobar'
+ , initializer => sub { die __PACKAGE__ }
+);
+
+package ClassBar;
+use Moose;
+
+has 'chas' => (
+ isa => 'Str'
+ , is => 'ro'
+ , default => 'Foobar'
+ , initializer => sub { die __PACKAGE__ }
+);
+
+package ClassBaz;
+use Moose;
+use MooseX::ClassAttribute;
+
+class_has 'chas' => (
+ isa => 'Str'
+ , is => 'rw'
+ , default => 'Foobar'
+ , trigger => sub { die __PACKAGE__ }
+);
+
+package ClassQuz;
+use Moose;
+
+has 'chas' => (
+ isa => 'Str'
+ , is => 'rw'
+ , default => 'Foobar'
+ , trigger => sub { die __PACKAGE__ }
+);
+
+
+package main;
+use Test::More tests => 4;
+
+eval { ClassFoo->new() };
+like ( $@, qr/ClassFoo/, "ClassFoo's class_has (ClassAttribute) initializer fires" );
+
+diag( qq{
+ IIRC: This is a bug, the default/initializer is supposed to be order dependant on
+ the attribute, unfortunately this module borks that.
+} );
+
+eval { ClassBar->new() };
+like ( $@, qr/ClassBar/, "ClassBar's has (non-ClassAttribute) initializer fires" );
+
+eval { ClassBaz->new->chas('foobar') };
+like ( $@, qr/ClassBaz/, "ClassBaz's class_has (ClassAttribute) trigger fires" );
+
+eval { ClassQuz->new->chas('foobar') };
+like ( $@, qr/ClassQuz/, "ClassQuz's has (non-ClassAttribute) trigger fires" );
+
+=head1 DONATIONS
+
+If you'd like to thank me for the work I've done on this module,
+please consider making a "donation" to me via PayPal. I spend a lot of
+free time creating free software, and would appreciate any support
+you'd care to offer.
+
+Please note that B<I am not suggesting that you must do this> in order
+for me to continue working on this particular software. I will
+ continue to do so, inasmuch as I have in the past, for as long as it
+ interests me.
+
+ Similarly, a donation made in this way will probably not make me work
+ on this software much more, unless I get so many donations that I can
+ consider working on free software full time, which seems unlikely at
+ best.
+
+ To donate, log into PayPal contact me at me+freemoney@evancarroll.com
+
--
1.6.0.4