This is an automated email from the git hooks/post-receive script.

gregoa pushed a commit to annotated tag release-1.000
in repository libclass-tiny-perl.

commit 1a3417d88c7b448003b95123bda6319efb645fd1
Author: David Golden <dagol...@cpan.org>
Date:   Tue Jul 15 20:35:50 2014 -0400

    Document using BUILD for required attribute checks
    
    Fixes #14
---
 lib/Class/Tiny.pm | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/lib/Class/Tiny.pm b/lib/Class/Tiny.pm
index 6e99e2a..c45a481 100644
--- a/lib/Class/Tiny.pm
+++ b/lib/Class/Tiny.pm
@@ -337,13 +337,19 @@ by the constructor from the furthest parent class down to 
the child class after
 the object has been created.
 
 It is passed the constructor arguments as a hash reference.  The return value
-is ignored.  Use C<BUILD> for validation or setting default values that
-depend on other attributes.
+is ignored.  Use C<BUILD> for validation, checking required attributes or
+setting default values that depend on other attributes.
 
     sub BUILD {
         my ($self, $args) = @_;
-        $self->msg( "Hello " . $self->name );
+
+        for my $req ( qw/name age/ ) {
+            croak "$req attribute required" unless defined $self->$req;
+        }
+
         croak "Age must be non-negative" if $self->age < 0;
+
+        $self->msg( "Hello " . $self->name );
     }
 
 The argument reference is a copy, so deleting elements won't affect data in the

-- 
Alioth's /usr/local/bin/git-commit-notice on 
/srv/git.debian.org/git/pkg-perl/packages/libclass-tiny-perl.git

_______________________________________________
Pkg-perl-cvs-commits mailing list
Pkg-perl-cvs-commits@lists.alioth.debian.org
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-perl-cvs-commits

Reply via email to