From: Cory Watson Date: Tue, 1 Dec 2009 21:48:06 +0000 (-0600) Subject: First commit. X-Git-Tag: 0.05~13 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=5447ee457d5fd503926799cb8efb8552bdb4764d;p=gitmo%2FMooseX-UndefTolerant.git First commit. --- 5447ee457d5fd503926799cb8efb8552bdb4764d diff --git a/Changes b/Changes new file mode 100644 index 0000000..7616469 --- /dev/null +++ b/Changes @@ -0,0 +1,5 @@ +Revision history for MooseX-Attribute-UndefTolerant + +0.01 Date/time + First version, released on an unsuspecting world. + diff --git a/MANIFEST b/MANIFEST new file mode 100644 index 0000000..f68e82c --- /dev/null +++ b/MANIFEST @@ -0,0 +1,8 @@ +Changes +MANIFEST +Makefile.PL +README +lib/MooseX/Attribute/UndefTolerant.pm +t/00-load.t +t/pod-coverage.t +t/pod.t diff --git a/Makefile.PL b/Makefile.PL new file mode 100644 index 0000000..185aa00 --- /dev/null +++ b/Makefile.PL @@ -0,0 +1,12 @@ +use inc::Module::Install; + +name 'MooseX-Attribute-UndefTolerant'; +all_from 'lib/MooseX/Attribute/UndefTolerant.pm'; +author q{Cory G Watson }; +license 'perl'; + +build_requires 'Test::More'; + +requires 'Moose'; + +WriteAll; diff --git a/README b/README new file mode 100644 index 0000000..75803b3 --- /dev/null +++ b/README @@ -0,0 +1,55 @@ +MooseX-Attribute-UndefTolerant + +The README is used to introduce the module and provide instructions on +how to install the module, any machine dependencies it may have (for +example C compilers and installed libraries) and any other information +that should be provided before the module is installed. + +A README file is required for CPAN modules since CPAN extracts the README +file from a module distribution so that people browsing the archive +can use it to get an idea of the module's uses. It is usually a good idea +to provide version information here so that people can decide whether +fixes for the module are worth downloading. + + +INSTALLATION + +To install this module, run the following commands: + + perl Makefile.PL + make + make test + make install + +SUPPORT AND DOCUMENTATION + +After installing, you can find documentation for this module with the +perldoc command. + + perldoc MooseX::Attribute::UndefTolerant + +You can also look for information at: + + RT, CPAN's request tracker + http://rt.cpan.org/NoAuth/Bugs.html?Dist=MooseX-Attribute-UndefTolerant + + AnnoCPAN, Annotated CPAN documentation + http://annocpan.org/dist/MooseX-Attribute-UndefTolerant + + CPAN Ratings + http://cpanratings.perl.org/d/MooseX-Attribute-UndefTolerant + + Search CPAN + http://search.cpan.org/dist/MooseX-Attribute-UndefTolerant/ + + +COPYRIGHT AND LICENCE + +Copyright (C) 2009 Cory G Watson + +This program is free software; you can redistribute it and/or modify it +under the terms of either: the GNU General Public License as published +by the Free Software Foundation; or the Artistic License. + +See http://dev.perl.org/licenses/ for more information. + diff --git a/ignore.txt b/ignore.txt new file mode 100644 index 0000000..5a3fcd6 --- /dev/null +++ b/ignore.txt @@ -0,0 +1,10 @@ +blib* +Makefile +Makefile.old +Build +_build* +pm_to_blib* +*.tar.gz +.lwpcookies +MooseX-Attribute-UndefTolerant-* +cover_db diff --git a/lib/MooseX/UndefTolerant.pm b/lib/MooseX/UndefTolerant.pm new file mode 100644 index 0000000..419a7b4 --- /dev/null +++ b/lib/MooseX/UndefTolerant.pm @@ -0,0 +1,68 @@ +package MooseX::UndefTolerant; +use strict; +use warnings; + +use Moose qw(); +use Moose::Exporter; +use Moose::Util::MetaRole; + +use MooseX::UndefTolerant::Attribute; + +our $VERSION = '0.01'; + +Moose::Exporter->setup_import_methods(); + +sub init_meta { + my (undef, %options) = @_; + + Moose->init_meta(%options); + + return Moose::Util::MetaRole::apply_metaclass_roles( + for_class => $options{for_class}, + attribute_metaclass_roles => [ 'MooseX::UndefTolerant::Attribute' ] + ); +} + +1; + +__END__ + +=head1 NAME + +MooseX::Attribute::UndefTolerant - The great new MooseX::Attribute::UndefTolerant! + +=head1 SYNOPSIS + + use MooseX::Attribute::UndefTolerant; + + +=head1 AUTHOR + +Cory G Watson, C<< >> + +=head1 ACKNOWLEDGEMENTS + +Hans Dieter Pearcey (confound) + +Jesse Luehrs (doy) + +Tomas Doran (t0m) + +Dylan Hardison (dylan) + +Jay Shirley (jshirley) + +Mike Eldridge (diz) + +=head1 COPYRIGHT & LICENSE + +Copyright 2009 Cory G Watson. + +This program is free software; you can redistribute it and/or modify it +under the terms of either: the GNU General Public License as published +by the Free Software Foundation; or the Artistic License. + +See http://dev.perl.org/licenses/ for more information. + + +=cut diff --git a/lib/MooseX/UndefTolerant/Attribute.pm b/lib/MooseX/UndefTolerant/Attribute.pm new file mode 100644 index 0000000..e1aee78 --- /dev/null +++ b/lib/MooseX/UndefTolerant/Attribute.pm @@ -0,0 +1,15 @@ +package MooseX::UndefTolerant::Attribute; +use Moose::Role; + +around('initialize_instance_slot', sub{ + my $orig = shift; + my $self = shift; + + # If the parameter passed in was undef, quietly do nothing but return + return unless defined($_->[2]); + + # If it was defined, call the real init slot method + $self->$orig(@_) +}); + +1; \ No newline at end of file diff --git a/t/00-load.t b/t/00-load.t new file mode 100644 index 0000000..2fc2838 --- /dev/null +++ b/t/00-load.t @@ -0,0 +1,9 @@ +#!perl -T + +use Test::More tests => 1; + +BEGIN { + use_ok( 'MooseX::Attribute::UndefTolerant' ); +} + +diag( "Testing MooseX::Attribute::UndefTolerant $MooseX::Attribute::UndefTolerant::VERSION, Perl $], $^X" ); diff --git a/t/attribute.t b/t/attribute.t new file mode 100644 index 0000000..db0215f --- /dev/null +++ b/t/attribute.t @@ -0,0 +1,41 @@ +use Test::More; + +package Foo; +use Moose; + +has 'bar' => ( + traits => [ qw(MooseX::UndefTolerant::Attribute)], + is => 'ro', + isa => 'Num', + predicate => 'has_bar' +); + +package Foo2; +use Moose; +use MooseX::UndefTolerant; + +has 'bar' => ( + is => 'ro', + isa => 'Num', + predicate => 'has_bar' +); + +package main; + +{ + my $foo = Foo->new; + ok(!$foo->has_bar); +} + +{ + my $foo = Foo->new(bar => undef); + ok(!$foo->has_bar); +} + +{ + my $foo = Foo2->new(bar => undef); + ok(!$foo->has_bar); +} + + +done_testing; \ No newline at end of file