use strict;
use warnings;
-use Test::More tests => 10;
+use Test::More tests => 26;
use Test::Exception;
-use Scalar::Util 'isweak';
-
BEGIN {
use_ok('Moose');
}
has 'header' => (is => 'rw', isa => 'HTTPHeader', coerce => 1);
}
-my $engine = Engine->new();
-isa_ok($engine, 'Engine');
+{
+ my $engine = Engine->new();
+ isa_ok($engine, 'Engine');
+
+ # try with arrays
+
+ lives_ok {
+ $engine->header([ 1, 2, 3 ]);
+ } '... type was coerced without incident';
+ isa_ok($engine->header, 'HTTPHeader');
+
+ is_deeply(
+ $engine->header->array,
+ [ 1, 2, 3 ],
+ '... got the right array value of the header');
+ ok(!defined($engine->header->hash), '... no hash value set');
+
+ # try with hash
+
+ lives_ok {
+ $engine->header({ one => 1, two => 2, three => 3 });
+ } '... type was coerced without incident';
+ isa_ok($engine->header, 'HTTPHeader');
+
+ is_deeply(
+ $engine->header->hash,
+ { one => 1, two => 2, three => 3 },
+ '... got the right hash value of the header');
+ ok(!defined($engine->header->array), '... no array value set');
+
+ dies_ok {
+ $engine->header("Foo");
+ } '... dies with the wrong type, even after coercion';
+
+ lives_ok {
+ $engine->header(HTTPHeader->new);
+ } '... lives with the right type, even after coercion';
+}
-# try with arrays
+{
+ my $engine = Engine->new(header => [ 1, 2, 3 ]);
+ isa_ok($engine, 'Engine');
-$engine->header([ 1, 2, 3 ]);
-isa_ok($engine->header, 'HTTPHeader');
+ isa_ok($engine->header, 'HTTPHeader');
-is_deeply(
- $engine->header->array,
- [ 1, 2, 3 ],
- '... got the right array value of the header');
-ok(!defined($engine->header->hash), '... no hash value set');
+ is_deeply(
+ $engine->header->array,
+ [ 1, 2, 3 ],
+ '... got the right array value of the header');
+ ok(!defined($engine->header->hash), '... no hash value set');
+}
-# try with hash
+{
+ my $engine = Engine->new(header => { one => 1, two => 2, three => 3 });
+ isa_ok($engine, 'Engine');
-$engine->header({ one => 1, two => 2, three => 3 });
-isa_ok($engine->header, 'HTTPHeader');
+ isa_ok($engine->header, 'HTTPHeader');
-is_deeply(
- $engine->header->hash,
- { one => 1, two => 2, three => 3 },
- '... got the right hash value of the header');
-ok(!defined($engine->header->array), '... no array value set');
+ is_deeply(
+ $engine->header->hash,
+ { one => 1, two => 2, three => 3 },
+ '... got the right hash value of the header');
+ ok(!defined($engine->header->array), '... no array value set');
+}
-dies_ok {
- $engine->header("Foo");
-} '... dies with the wrong type, even after coercion';
+{
+ my $engine = Engine->new(header => HTTPHeader->new());
+ isa_ok($engine, 'Engine');
-lives_ok {
- $engine->header(HTTPHeader->new);
-} '... lives with the right type, even after coercion';
+ isa_ok($engine->header, 'HTTPHeader');
+ ok(!defined($engine->header->hash), '... no hash value set');
+ ok(!defined($engine->header->array), '... no array value set');
+}
+dies_ok {
+ Engine->new(header => 'Foo');
+} '... dies correctly with bad params';
+dies_ok {
+ Engine->new(header => \(my $var));
+} '... dies correctly with bad params';