[Yapcom-commit] rev 86 - lib/YAPC t

[prev] [thread] [next] [lurker] [Date index for 2003/11/28]

From: svn
Subject: [Yapcom-commit] rev 86 - lib/YAPC t
Date: 13:28 on 28 Nov 2003
Author: gabor
Date: 2003-11-28 13:28:21 +0200 (Fri, 28 Nov 2003)
New Revision: 86

Modified:
   lib/YAPC/Organizer.pm
   lib/YAPC/Person.pm
   t/01-adduser.t
Log:
add exception handling to YAPC::Person

Modified: lib/YAPC/Organizer.pm
===================================================================
--- lib/YAPC/Organizer.pm	2003-11-27 21:49:48 UTC (rev 85)
+++ lib/YAPC/Organizer.pm	2003-11-28 11:28:21 UTC (rev 86)
@@ -459,16 +459,19 @@
 # See logic in &lost_validation
     return $t->output unless $q->param('submit');
 
-    eval {
+    try {
        $person = YAPC::Person->new($q->Vars);
-    };
+    }
+     catch YAPC::Error with {
+      my $er = shift;
+      #$t->param(MESSAGE => 'There was an error in the provided data.');
+      $t->param(MESSAGE => $er);
+    }
+    catch Error with {
+      $t->param(MESSAGE => 'There was an error in the provided data.');
+      #$t->param(MESSAGE => 'Registration failed.');
+    } or return $t->output; # on error
 
-    if ($@) {
-       my $msg = $@;
-       # cannot register (duplicate email ?, other problem ?)
-       $t->param(MESSAGE => 'There was an error in the provided data.');
-       return $t->output;
-     }
 
      # success
      $self->send_email_with_validation_code($person);

Modified: lib/YAPC/Person.pm
===================================================================
--- lib/YAPC/Person.pm	2003-11-27 21:49:48 UTC (rev 85)
+++ lib/YAPC/Person.pm	2003-11-28 11:28:21 UTC (rev 86)
@@ -4,6 +4,7 @@
 use Carp;
 use YAPC::DBI;
 use base 'YAPC::DBI';
+use YAPC::Error;
 __PACKAGE__->set_up_table('people');
 __PACKAGE__->set_sql(total => qq{SELECT COUNT(*) total FROM people});
 __PACKAGE__->set_sql(validated => qq{SELECT COUNT(*) validated FROM people WHERE acked=1});
@@ -19,9 +20,9 @@
     croak("authcode should not be defined\n") if defined $arg{authcode};
     croak("id should not be defined\n") if defined $arg{id};
 
-    croak("No fname provided\n") if not $arg{fname};
-    croak("No lname provided\n") if not $arg{lname};
-    croak("No phone provided\n") if not $arg{phone};
+    throw YAPC::Error("No First Name provided\n") if not $arg{fname};
+    throw YAPC::Error("No Last Name provided\n") if not $arg{lname};
+    throw YAPC::Error("No Phone provided\n") if not $arg{phone};
 
     my @valid_args = qw(fname lname phone email password company pauseid url mongers bio);
 
@@ -29,7 +30,7 @@
         $arg{email} !~ /^[\w\d+=@.-]{5,}$/ or
         $arg{email} !~ /@/) {
 
-        croak("Bad e-mail given\n") 
+        throw YAPC::Error("Bad e-mail given\n") 
     }
     if ($arg{password} and $arg{password2} and 
         $arg{password} eq  $arg{password2}) {
@@ -38,7 +39,7 @@
        @passed_args{@valid_args}= @arg{@valid_args};
        __PACKAGE__->create(\%passed_args);  # could be $self->   also
     } else {
-       croak("Bad password pair given\n");
+       throw YAPC::Error("Bad password pair given\n");
     }
 }
 

Modified: t/01-adduser.t
===================================================================
--- t/01-adduser.t	2003-11-27 21:49:48 UTC (rev 85)
+++ t/01-adduser.t	2003-11-28 11:28:21 UTC (rev 86)
@@ -70,6 +70,8 @@
 
 
 ######## try to register users without one of the required fields (both undef and '' is checked)
+### this part tests the various error messages of YAPC::Person without checking the
+### exact phrases
 foreach my $field (qw(fname lname email password password2)) {
    eval {
      my %user = %{$people[2]};

Generated at 00:55 on 29 Nov 2003 by mariachi 0.51