Index: /trunk/Nebulous-Server/lib/Nebulous/Server.pm
===================================================================
--- /trunk/Nebulous-Server/lib/Nebulous/Server.pm	(revision 5497)
+++ /trunk/Nebulous-Server/lib/Nebulous/Server.pm	(revision 5498)
@@ -1,5 +1,5 @@
 # Copyright (c) 2004  Joshua Hoblitt
 #
-# $Id: Server.pm,v 1.13 2005-11-09 01:31:07 jhoblitt Exp $
+# $Id: Server.pm,v 1.14 2005-11-10 21:31:26 jhoblitt Exp $
 
 package Nebulous::Server;
@@ -75,4 +75,6 @@
             callbacks   => {
                 'is + integer' => sub { $_[0] =~ /^\d+$/ },
+                # check that the class requested is valid
+                'is valid class id' => sub { _is_valid_class_id( $_[0] ) },
             },
             default     => 0,
@@ -96,24 +98,4 @@
     # check that the comment isn't too long
     # check that the volume requested is valid
-
-    # check that the class requested is valid
-    if ( $class ) {
-        my $class_id;
-        eval {
-            my $query = $db->prepare_cached( $sql->get_class ); 
-            $query->execute( $class );
-            ( $class_id ) = $query->fetchrow_array;
-
-            $query->finish;
-        };
-        if ( $@ ) {
-            $db->rollback;
-            $log->logdie( "database error: $@" );
-        }
-
-        unless ( $class_id ) {
-            $log->logdie( "Invalid class ID: $class" );
-        }
-    }
 
     my $uri;
@@ -701,4 +683,23 @@
 }
 
+sub _is_valid_class_id {
+    my $class = shift;
+
+    my $class_id;
+    eval {
+        my $query = $db->prepare_cached( $sql->get_class ); 
+        $query->execute( $class );
+        ( $class_id ) = $query->fetchrow_array;
+
+        $query->finish;
+    };
+    if ( $@ ) {
+        $db->rollback;
+        $log->logdie( "database error: $@" );
+    }
+
+    return ( defined $class_id ) ? 1 : undef;
+}
+
 1;
 
Index: /trunk/Nebulous-Server/t/09_server_is_valid_class_id.t
===================================================================
--- /trunk/Nebulous-Server/t/09_server_is_valid_class_id.t	(revision 5498)
+++ /trunk/Nebulous-Server/t/09_server_is_valid_class_id.t	(revision 5498)
@@ -0,0 +1,42 @@
+#!/usr/bin/perl
+
+# Copryight (C) 2004-2005  Joshua Hoblitt
+#
+# $Id: 09_server_is_valid_class_id.t,v 1.1 2005-11-10 21:31:26 jhoblitt Exp $
+
+use strict;
+use warnings FATAL => qw( all );
+
+use Test::More tests => 3;
+
+use lib qw( ./t ./lib );
+
+use Nebulous::Server;
+use Nebulous::Util qw( :standard );
+use Test::Nebulous;
+
+my $neb = "Nebulous::Server";
+
+$neb->init(
+    dsn         => "DBI:mysql:database=test:host=localhost",
+    dbuser      => "test",
+    dbpasswd    => "",
+);
+
+*_is_valid_class_id = \&Nebulous::Server::_is_valid_class_id;
+
+Test::Nebulous->setup;
+
+# 0 is the default and is guarenteed to exist
+ok( _is_valid_class_id( 0 ), "default class id");
+
+Test::Nebulous->setup;
+
+# the test setup adds class id 1
+ok( _is_valid_class_id( 1 ), "custom class id");
+
+Test::Nebulous->setup;
+
+is( _is_valid_class_id( 99 ), undef, "invalid class id");
+
+Test::Nebulous->cleanup;
Index: /trunk/Nebulous/lib/Nebulous/Server.pm
===================================================================
--- /trunk/Nebulous/lib/Nebulous/Server.pm	(revision 5497)
+++ /trunk/Nebulous/lib/Nebulous/Server.pm	(revision 5498)
@@ -1,5 +1,5 @@
 # Copyright (c) 2004  Joshua Hoblitt
 #
-# $Id: Server.pm,v 1.13 2005-11-09 01:31:07 jhoblitt Exp $
+# $Id: Server.pm,v 1.14 2005-11-10 21:31:26 jhoblitt Exp $
 
 package Nebulous::Server;
@@ -75,4 +75,6 @@
             callbacks   => {
                 'is + integer' => sub { $_[0] =~ /^\d+$/ },
+                # check that the class requested is valid
+                'is valid class id' => sub { _is_valid_class_id( $_[0] ) },
             },
             default     => 0,
@@ -96,24 +98,4 @@
     # check that the comment isn't too long
     # check that the volume requested is valid
-
-    # check that the class requested is valid
-    if ( $class ) {
-        my $class_id;
-        eval {
-            my $query = $db->prepare_cached( $sql->get_class ); 
-            $query->execute( $class );
-            ( $class_id ) = $query->fetchrow_array;
-
-            $query->finish;
-        };
-        if ( $@ ) {
-            $db->rollback;
-            $log->logdie( "database error: $@" );
-        }
-
-        unless ( $class_id ) {
-            $log->logdie( "Invalid class ID: $class" );
-        }
-    }
 
     my $uri;
@@ -701,4 +683,23 @@
 }
 
+sub _is_valid_class_id {
+    my $class = shift;
+
+    my $class_id;
+    eval {
+        my $query = $db->prepare_cached( $sql->get_class ); 
+        $query->execute( $class );
+        ( $class_id ) = $query->fetchrow_array;
+
+        $query->finish;
+    };
+    if ( $@ ) {
+        $db->rollback;
+        $log->logdie( "database error: $@" );
+    }
+
+    return ( defined $class_id ) ? 1 : undef;
+}
+
 1;
 
Index: /trunk/Nebulous/t/09_server_is_valid_class_id.t
===================================================================
--- /trunk/Nebulous/t/09_server_is_valid_class_id.t	(revision 5498)
+++ /trunk/Nebulous/t/09_server_is_valid_class_id.t	(revision 5498)
@@ -0,0 +1,42 @@
+#!/usr/bin/perl
+
+# Copryight (C) 2004-2005  Joshua Hoblitt
+#
+# $Id: 09_server_is_valid_class_id.t,v 1.1 2005-11-10 21:31:26 jhoblitt Exp $
+
+use strict;
+use warnings FATAL => qw( all );
+
+use Test::More tests => 3;
+
+use lib qw( ./t ./lib );
+
+use Nebulous::Server;
+use Nebulous::Util qw( :standard );
+use Test::Nebulous;
+
+my $neb = "Nebulous::Server";
+
+$neb->init(
+    dsn         => "DBI:mysql:database=test:host=localhost",
+    dbuser      => "test",
+    dbpasswd    => "",
+);
+
+*_is_valid_class_id = \&Nebulous::Server::_is_valid_class_id;
+
+Test::Nebulous->setup;
+
+# 0 is the default and is guarenteed to exist
+ok( _is_valid_class_id( 0 ), "default class id");
+
+Test::Nebulous->setup;
+
+# the test setup adds class id 1
+ok( _is_valid_class_id( 1 ), "custom class id");
+
+Test::Nebulous->setup;
+
+is( _is_valid_class_id( 99 ), undef, "invalid class id");
+
+Test::Nebulous->cleanup;
