From c79f16aa7fdad589f8b29b0a9d4ae39b66f6efbe Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Thu, 24 Jun 2010 13:54:24 -0500 Subject: convert to new dzil stuff --- .gitignore | 2 + Changes | 6 +-- dist.ini | 5 +- lib/MooseX/Attribute/Shorthand.pm | 53 +------------------- t/000-load.t | 9 ---- t/001-basic.t | 77 ---------------------------- t/002-custom-exporter.t | 45 ----------------- t/003-mop.t | 23 --------- t/004-roles.t | 89 -------------------------------- t/01-basic.t | 77 ++++++++++++++++++++++++++++ t/02-custom-exporter.t | 45 +++++++++++++++++ t/03-mop.t | 23 +++++++++ t/04-roles.t | 89 ++++++++++++++++++++++++++++++++ t/10-lazy-require.t | 103 ++++++++++++++++++++++++++++++++++++++ t/100-lazy-require.t | 103 -------------------------------------- 15 files changed, 346 insertions(+), 403 deletions(-) delete mode 100644 t/000-load.t delete mode 100644 t/001-basic.t delete mode 100644 t/002-custom-exporter.t delete mode 100644 t/003-mop.t delete mode 100644 t/004-roles.t create mode 100644 t/01-basic.t create mode 100644 t/02-custom-exporter.t create mode 100644 t/03-mop.t create mode 100644 t/04-roles.t create mode 100644 t/10-lazy-require.t delete mode 100644 t/100-lazy-require.t diff --git a/.gitignore b/.gitignore index c38068c..42b9db0 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,5 @@ Makefile.old nytprof.out MANIFEST.bak *.sw[po] +.build +MooseX-Attribute-Shorthand-* diff --git a/Changes b/Changes index fcbad0c..c0420c9 100644 --- a/Changes +++ b/Changes @@ -1,4 +1,4 @@ -Revision history for MooseX::Attribute::Shorthand +Revision history for MooseX-Attribute-Shorthand -0.01 - Initial release +{{$NEXT}} + - Initial release diff --git a/dist.ini b/dist.ini index 7a932a1..9b004a0 100644 --- a/dist.ini +++ b/dist.ini @@ -1,11 +1,10 @@ name = MooseX-Attribute-Shorthand -version = 0.01 author = Jesse Luehrs license = Perl_5 copyright_holder = Jesse Luehrs -abstract = -[@Classic] +[@DOY] +dist = MooseX-Attribute-Shorthand [Prereq] Moose = 1.09 diff --git a/lib/MooseX/Attribute/Shorthand.pm b/lib/MooseX/Attribute/Shorthand.pm index aef1a0f..f66e71f 100644 --- a/lib/MooseX/Attribute/Shorthand.pm +++ b/lib/MooseX/Attribute/Shorthand.pm @@ -1,14 +1,11 @@ package MooseX::Attribute::Shorthand; use strict; use warnings; +# ABSTRACT: write custom attribute option bundles use Moose (); use Scalar::Util qw(reftype); -=head1 NAME - -MooseX::Attribute::Shorthand - - =head1 SYNOPSIS @@ -69,55 +66,9 @@ sub import { ); } -=head1 BUGS - -No known bugs. - -Please report any bugs through RT: email -C, or browse to -L. - =head1 SEE ALSO - -=head1 SUPPORT - -You can find this documentation for this module with the perldoc command. - - perldoc MooseX::Attribute::Shorthand - -You can also look for information at: - -=over 4 - -=item * AnnoCPAN: Annotated CPAN documentation - -L - -=item * CPAN Ratings - -L - -=item * RT: CPAN's request tracker - -L - -=item * Search CPAN - -L - -=back - -=head1 AUTHOR - - Jesse Luehrs - -=head1 COPYRIGHT AND LICENSE - -This software is copyright (c) 2010 by Jesse Luehrs. - -This is free software; you can redistribute it and/or modify it under -the same terms as perl itself. +L =cut diff --git a/t/000-load.t b/t/000-load.t deleted file mode 100644 index cffc9cb..0000000 --- a/t/000-load.t +++ /dev/null @@ -1,9 +0,0 @@ -#!/usr/bin/env perl -use strict; -use warnings; -use Test::More tests => 1; - -package Foo; -use Moose; -::use_ok('MooseX::Attribute::Shorthand') - or ::BAIL_OUT("couldn't load MooseX::Attribute::Shorthand"); diff --git a/t/001-basic.t b/t/001-basic.t deleted file mode 100644 index eeaf168..0000000 --- a/t/001-basic.t +++ /dev/null @@ -1,77 +0,0 @@ -#!/usr/bin/env perl -use strict; -use warnings; -use Test::More; -use Test::Exception; - -{ - package Foo; - use Moose; - use MooseX::Attribute::Shorthand string => { - is => 'ro', - isa => 'Str', - default => sub { $_[1] }, - -meta_attr_options => { isa => 'Str' }, - }; - - has foo => (string => 'FOO'); -} - -my $foo = Foo->new; -is($foo->foo, 'FOO', "expanded properly"); -dies_ok { $foo->foo('sldkfj') } "expanded properly"; - -{ - package Bar; - use Moose; - use MooseX::Attribute::Shorthand my_lazy_build => { - lazy => 1, - builder => sub { "_build_$_[0]" }, - predicate => sub { - my $name = shift; - my $private = $name =~ s/^_//; - $private ? "_has_$name" : "has_$name"; - }, - clearer => sub { - my $name = shift; - my $private = $name =~ s/^_//; - $private ? "_clear_$name" : "clear_$name"; - }, - }; - - has public => ( - is => 'ro', - isa => 'Str', - my_lazy_build => 1, - ); - - sub _build_public { 'PUBLIC' } - - has _private => ( - is => 'ro', - isa => 'Str', - my_lazy_build => 1, - ); - - sub _build__private { 'PRIVATE' } -} - -my $bar = Bar->new; -can_ok($bar, $_) for qw(has_public clear_public _has_private _clear_private); -ok(!$bar->can($_), "Bar can't $_") for qw(has__private clear__private); - -ok(!$bar->has_public, "doesn't have a value yet"); -is($bar->public, 'PUBLIC', "gets a lazy value"); -ok($bar->has_public, "has a value now"); -$bar->clear_public; -ok(!$bar->has_public, "doesn't have a value again"); -dies_ok { $bar->public('sldkfj') } "other options aren't overwritten"; - -ok(!$bar->_has_private, "doesn't have a value yet"); -is($bar->_private, 'PRIVATE', "gets a lazy value"); -ok($bar->_has_private, "has a value now"); -$bar->_clear_private; -ok(!$bar->_has_private, "doesn't have a value again"); -dies_ok { $bar->_private('sldkfj') } "other options aren't overwritten"; - -done_testing; diff --git a/t/002-custom-exporter.t b/t/002-custom-exporter.t deleted file mode 100644 index b4efe98..0000000 --- a/t/002-custom-exporter.t +++ /dev/null @@ -1,45 +0,0 @@ -#!/usr/bin/env perl -use strict; -use warnings; -use Test::More; -use Test::Exception; - -BEGIN { - package Foo::Exporter; - use Moose (); - use MooseX::Attribute::Shorthand (); - use Moose::Exporter; - - my ($import) = Moose::Exporter->build_import_methods( - also => ['Moose'], - install => ['unimport'], - ); - - sub import { - my $class = caller; - Moose->init_meta(for_class => $class); - MooseX::Attribute::Shorthand->import( - -for_class => $class, - string => { - is => 'ro', - isa => 'Str', - default => sub { $_[1] }, - -meta_attr_options => { isa => 'Str' }, - }, - ); - goto $import; - } -} - -{ - package Foo; - BEGIN { Foo::Exporter->import } - - has foo => (string => 'FOO'); -} - -my $foo = Foo->new; -is($foo->foo, 'FOO', "got correct options"); -dies_ok { $foo->foo('lsdkfj') } "got correct options"; - -done_testing; diff --git a/t/003-mop.t b/t/003-mop.t deleted file mode 100644 index 53b0b2e..0000000 --- a/t/003-mop.t +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/env perl -use strict; -use warnings; -use Test::More; - -{ - package Foo; - use Moose; - use MooseX::Attribute::Shorthand string => { - is => 'ro', - isa => 'Str', - default => sub { $_[1] }, - -meta_attr_options => { isa => 'Str' }, - }; - - has foo => (string => 'FOO'); -} - -my $attr = Foo->meta->get_attribute('foo'); -can_ok($attr, 'string'); -is($attr->string, 'FOO', "attribute set properly"); - -done_testing; diff --git a/t/004-roles.t b/t/004-roles.t deleted file mode 100644 index 6b32005..0000000 --- a/t/004-roles.t +++ /dev/null @@ -1,89 +0,0 @@ -#!/usr/bin/env perl -use strict; -use warnings; -use Test::More; -use Test::Exception; - -{ - package Foo::Role; - use Moose::Role; - use MooseX::Attribute::Shorthand string => { - is => 'ro', - isa => 'Str', - default => sub { $_[1] }, - -meta_attr_options => { isa => 'Str' }, - }; - - has foo => (string => 'FOO'); -} - -{ - package Foo; - use Moose; - with 'Foo::Role'; -} - -my $foo = Foo->new; -is($foo->foo, 'FOO', "expanded properly"); -dies_ok { $foo->foo('sldkfj') } "expanded properly"; - -{ - package Bar::Role; - use Moose::Role; - use MooseX::Attribute::Shorthand my_lazy_build => { - lazy => 1, - builder => sub { "_build_$_[0]" }, - predicate => sub { - my $name = shift; - my $private = $name =~ s/^_//; - $private ? "_has_$name" : "has_$name"; - }, - clearer => sub { - my $name = shift; - my $private = $name =~ s/^_//; - $private ? "_clear_$name" : "clear_$name"; - }, - }; - - has public => ( - is => 'ro', - isa => 'Str', - my_lazy_build => 1, - ); - - sub _build_public { 'PUBLIC' } - - has _private => ( - is => 'ro', - isa => 'Str', - my_lazy_build => 1, - ); - - sub _build__private { 'PRIVATE' } -} - -{ - package Bar; - use Moose; - with 'Bar::Role'; -} - -my $bar = Bar->new; -can_ok($bar, $_) for qw(has_public clear_public _has_private _clear_private); -ok(!$bar->can($_), "Bar can't $_") for qw(has__private clear__private); - -ok(!$bar->has_public, "doesn't have a value yet"); -is($bar->public, 'PUBLIC', "gets a lazy value"); -ok($bar->has_public, "has a value now"); -$bar->clear_public; -ok(!$bar->has_public, "doesn't have a value again"); -dies_ok { $bar->public('sldkfj') } "other options aren't overwritten"; - -ok(!$bar->_has_private, "doesn't have a value yet"); -is($bar->_private, 'PRIVATE', "gets a lazy value"); -ok($bar->_has_private, "has a value now"); -$bar->_clear_private; -ok(!$bar->_has_private, "doesn't have a value again"); -dies_ok { $bar->_private('sldkfj') } "other options aren't overwritten"; - -done_testing; diff --git a/t/01-basic.t b/t/01-basic.t new file mode 100644 index 0000000..eeaf168 --- /dev/null +++ b/t/01-basic.t @@ -0,0 +1,77 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use Test::More; +use Test::Exception; + +{ + package Foo; + use Moose; + use MooseX::Attribute::Shorthand string => { + is => 'ro', + isa => 'Str', + default => sub { $_[1] }, + -meta_attr_options => { isa => 'Str' }, + }; + + has foo => (string => 'FOO'); +} + +my $foo = Foo->new; +is($foo->foo, 'FOO', "expanded properly"); +dies_ok { $foo->foo('sldkfj') } "expanded properly"; + +{ + package Bar; + use Moose; + use MooseX::Attribute::Shorthand my_lazy_build => { + lazy => 1, + builder => sub { "_build_$_[0]" }, + predicate => sub { + my $name = shift; + my $private = $name =~ s/^_//; + $private ? "_has_$name" : "has_$name"; + }, + clearer => sub { + my $name = shift; + my $private = $name =~ s/^_//; + $private ? "_clear_$name" : "clear_$name"; + }, + }; + + has public => ( + is => 'ro', + isa => 'Str', + my_lazy_build => 1, + ); + + sub _build_public { 'PUBLIC' } + + has _private => ( + is => 'ro', + isa => 'Str', + my_lazy_build => 1, + ); + + sub _build__private { 'PRIVATE' } +} + +my $bar = Bar->new; +can_ok($bar, $_) for qw(has_public clear_public _has_private _clear_private); +ok(!$bar->can($_), "Bar can't $_") for qw(has__private clear__private); + +ok(!$bar->has_public, "doesn't have a value yet"); +is($bar->public, 'PUBLIC', "gets a lazy value"); +ok($bar->has_public, "has a value now"); +$bar->clear_public; +ok(!$bar->has_public, "doesn't have a value again"); +dies_ok { $bar->public('sldkfj') } "other options aren't overwritten"; + +ok(!$bar->_has_private, "doesn't have a value yet"); +is($bar->_private, 'PRIVATE', "gets a lazy value"); +ok($bar->_has_private, "has a value now"); +$bar->_clear_private; +ok(!$bar->_has_private, "doesn't have a value again"); +dies_ok { $bar->_private('sldkfj') } "other options aren't overwritten"; + +done_testing; diff --git a/t/02-custom-exporter.t b/t/02-custom-exporter.t new file mode 100644 index 0000000..b4efe98 --- /dev/null +++ b/t/02-custom-exporter.t @@ -0,0 +1,45 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use Test::More; +use Test::Exception; + +BEGIN { + package Foo::Exporter; + use Moose (); + use MooseX::Attribute::Shorthand (); + use Moose::Exporter; + + my ($import) = Moose::Exporter->build_import_methods( + also => ['Moose'], + install => ['unimport'], + ); + + sub import { + my $class = caller; + Moose->init_meta(for_class => $class); + MooseX::Attribute::Shorthand->import( + -for_class => $class, + string => { + is => 'ro', + isa => 'Str', + default => sub { $_[1] }, + -meta_attr_options => { isa => 'Str' }, + }, + ); + goto $import; + } +} + +{ + package Foo; + BEGIN { Foo::Exporter->import } + + has foo => (string => 'FOO'); +} + +my $foo = Foo->new; +is($foo->foo, 'FOO', "got correct options"); +dies_ok { $foo->foo('lsdkfj') } "got correct options"; + +done_testing; diff --git a/t/03-mop.t b/t/03-mop.t new file mode 100644 index 0000000..53b0b2e --- /dev/null +++ b/t/03-mop.t @@ -0,0 +1,23 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use Test::More; + +{ + package Foo; + use Moose; + use MooseX::Attribute::Shorthand string => { + is => 'ro', + isa => 'Str', + default => sub { $_[1] }, + -meta_attr_options => { isa => 'Str' }, + }; + + has foo => (string => 'FOO'); +} + +my $attr = Foo->meta->get_attribute('foo'); +can_ok($attr, 'string'); +is($attr->string, 'FOO', "attribute set properly"); + +done_testing; diff --git a/t/04-roles.t b/t/04-roles.t new file mode 100644 index 0000000..6b32005 --- /dev/null +++ b/t/04-roles.t @@ -0,0 +1,89 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use Test::More; +use Test::Exception; + +{ + package Foo::Role; + use Moose::Role; + use MooseX::Attribute::Shorthand string => { + is => 'ro', + isa => 'Str', + default => sub { $_[1] }, + -meta_attr_options => { isa => 'Str' }, + }; + + has foo => (string => 'FOO'); +} + +{ + package Foo; + use Moose; + with 'Foo::Role'; +} + +my $foo = Foo->new; +is($foo->foo, 'FOO', "expanded properly"); +dies_ok { $foo->foo('sldkfj') } "expanded properly"; + +{ + package Bar::Role; + use Moose::Role; + use MooseX::Attribute::Shorthand my_lazy_build => { + lazy => 1, + builder => sub { "_build_$_[0]" }, + predicate => sub { + my $name = shift; + my $private = $name =~ s/^_//; + $private ? "_has_$name" : "has_$name"; + }, + clearer => sub { + my $name = shift; + my $private = $name =~ s/^_//; + $private ? "_clear_$name" : "clear_$name"; + }, + }; + + has public => ( + is => 'ro', + isa => 'Str', + my_lazy_build => 1, + ); + + sub _build_public { 'PUBLIC' } + + has _private => ( + is => 'ro', + isa => 'Str', + my_lazy_build => 1, + ); + + sub _build__private { 'PRIVATE' } +} + +{ + package Bar; + use Moose; + with 'Bar::Role'; +} + +my $bar = Bar->new; +can_ok($bar, $_) for qw(has_public clear_public _has_private _clear_private); +ok(!$bar->can($_), "Bar can't $_") for qw(has__private clear__private); + +ok(!$bar->has_public, "doesn't have a value yet"); +is($bar->public, 'PUBLIC', "gets a lazy value"); +ok($bar->has_public, "has a value now"); +$bar->clear_public; +ok(!$bar->has_public, "doesn't have a value again"); +dies_ok { $bar->public('sldkfj') } "other options aren't overwritten"; + +ok(!$bar->_has_private, "doesn't have a value yet"); +is($bar->_private, 'PRIVATE', "gets a lazy value"); +ok($bar->_has_private, "has a value now"); +$bar->_clear_private; +ok(!$bar->_has_private, "doesn't have a value again"); +dies_ok { $bar->_private('sldkfj') } "other options aren't overwritten"; + +done_testing; diff --git a/t/10-lazy-require.t b/t/10-lazy-require.t new file mode 100644 index 0000000..fbe2c81 --- /dev/null +++ b/t/10-lazy-require.t @@ -0,0 +1,103 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use Test::More; +use Test::Exception; + +{ + package My::MooseX::LazyRequire; + use MooseX::Attribute::Shorthand (); + + sub import { + my $class = caller; + MooseX::Attribute::Shorthand->import( + -for_class => $class, + lazy_required => { + lazy => 1, + required => 1, + default => sub { + my $name = shift; + sub { + Carp::confess "Attribute $name must be provided before calling reader"; + } + }, + }, + ); + } +} + +{ + package Foo; + use Moose; + BEGIN { My::MooseX::LazyRequire->import } + + has bar => ( + is => 'ro', + lazy_required => 1, + ); + + has baz => ( + is => 'ro', + builder => '_build_baz', + ); + + sub _build_baz { shift->bar + 1 } +} + +{ + my $foo; + lives_ok(sub { + $foo = Foo->new(bar => 42); + }); + is($foo->baz, 43); +} + +{ + my $foo; + lives_ok(sub { + $foo = Foo->new(baz => 23); + }); + is($foo->baz, 23); +} + +throws_ok(sub { + Foo->new; +}, qr/must be provided/); + +{ + package Bar; + use Moose; + BEGIN { My::MooseX::LazyRequire->import } + + has foo => ( + is => 'rw', + lazy_required => 1, + ); + + has baz => ( + is => 'ro', + lazy => 1, + builder => '_build_baz', + ); + + sub _build_baz { shift->foo + 1 } +} + +{ + my $bar = Bar->new; + + throws_ok(sub { + $bar->baz; + }, qr/must be provided/); + + $bar->foo(42); + + my $baz; + lives_ok(sub { + $baz = $bar->baz; + }); + + is($baz, 43); +} + +done_testing; diff --git a/t/100-lazy-require.t b/t/100-lazy-require.t deleted file mode 100644 index fbe2c81..0000000 --- a/t/100-lazy-require.t +++ /dev/null @@ -1,103 +0,0 @@ -#!/usr/bin/env perl -use strict; -use warnings; -use Test::More; -use Test::Exception; - -{ - package My::MooseX::LazyRequire; - use MooseX::Attribute::Shorthand (); - - sub import { - my $class = caller; - MooseX::Attribute::Shorthand->import( - -for_class => $class, - lazy_required => { - lazy => 1, - required => 1, - default => sub { - my $name = shift; - sub { - Carp::confess "Attribute $name must be provided before calling reader"; - } - }, - }, - ); - } -} - -{ - package Foo; - use Moose; - BEGIN { My::MooseX::LazyRequire->import } - - has bar => ( - is => 'ro', - lazy_required => 1, - ); - - has baz => ( - is => 'ro', - builder => '_build_baz', - ); - - sub _build_baz { shift->bar + 1 } -} - -{ - my $foo; - lives_ok(sub { - $foo = Foo->new(bar => 42); - }); - is($foo->baz, 43); -} - -{ - my $foo; - lives_ok(sub { - $foo = Foo->new(baz => 23); - }); - is($foo->baz, 23); -} - -throws_ok(sub { - Foo->new; -}, qr/must be provided/); - -{ - package Bar; - use Moose; - BEGIN { My::MooseX::LazyRequire->import } - - has foo => ( - is => 'rw', - lazy_required => 1, - ); - - has baz => ( - is => 'ro', - lazy => 1, - builder => '_build_baz', - ); - - sub _build_baz { shift->foo + 1 } -} - -{ - my $bar = Bar->new; - - throws_ok(sub { - $bar->baz; - }, qr/must be provided/); - - $bar->foo(42); - - my $baz; - lives_ok(sub { - $baz = $bar->baz; - }); - - is($baz, 43); -} - -done_testing; -- cgit v1.2.3-54-g00ecf