From 02de7898f135026608eb566fb0114cb6bbf76803 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Thu, 7 May 2009 23:23:53 -0500 Subject: expand the mx-globref test a bit more --- t/033-moosex-globref.t | 52 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) (limited to 't') diff --git a/t/033-moosex-globref.t b/t/033-moosex-globref.t index 9c20893..6a8b4f6 100644 --- a/t/033-moosex-globref.t +++ b/t/033-moosex-globref.t @@ -5,8 +5,12 @@ use Test::More; BEGIN { eval "use MooseX::GlobRef ()"; plan skip_all => "MooseX::GlobRef is required for this test" if $@; - plan tests => 2; + plan tests => 10; } +# XXX: the way the IO modules are loaded means we can't just rely on cmop to +# load these properly/: +use IO::Handle; +use IO::File; BEGIN { require Moose; @@ -42,8 +46,54 @@ has bar => ( sub FOREIGNBUILDARGS { return } +package IO::File::Moose; +BEGIN { Foo::Exporter->import } +extends 'IO::File'; + +has baz => ( + is => 'rw', + isa => 'Str', +); + +sub FOREIGNBUILDARGS { return } + package main; my $handle = IO::Handle::Moose->new(bar => 'BAR'); is($handle->bar, 'BAR', 'moose accessor works properly'); $handle->bar('RAB'); is($handle->bar, 'RAB', 'moose accessor works properly (setting)'); +IO::Handle::Moose->meta->make_immutable; +$handle = IO::Handle::Moose->new(bar => 'BAR'); +is($handle->bar, 'BAR', 'moose accessor works properly'); +$handle->bar('RAB'); +is($handle->bar, 'RAB', 'moose accessor works properly (setting)'); + +SKIP: { + my $fh = IO::File::Moose->new(baz => 'BAZ'); + open $fh, "+>", undef + or skip "couldn't open a temporary file", 4; + is($fh->baz, 'BAZ', "accessor works"); + $fh->baz('ZAB'); + is($fh->baz, 'ZAB', "accessor works (writing)"); + $fh->print("foo\n"); + print $fh "bar\n"; + $fh->seek(0, 0); + my $buf; + $fh->read($buf, 8); + is($buf, "foo\nbar\n", "filehandle still works as normal"); +} +IO::File::Moose->meta->make_immutable; +SKIP: { + my $fh = IO::File::Moose->new(baz => 'BAZ'); + open $fh, "+>", undef + or skip "couldn't open a temporary file", 4; + is($fh->baz, 'BAZ', "accessor works"); + $fh->baz('ZAB'); + is($fh->baz, 'ZAB', "accessor works (writing)"); + $fh->print("foo\n"); + print $fh "bar\n"; + $fh->seek(0, 0); + my $buf; + $fh->read($buf, 8); + is($buf, "foo\nbar\n", "filehandle still works as normal"); +} -- cgit v1.2.3-54-g00ecf