[system] / trunk / webwork2 / lib / WeBWorK / DB / Webwork.pm Repository:
ViewVC logotype

View of /trunk/webwork2/lib/WeBWorK/DB/Webwork.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 361 - (download) (as text) (annotate)
Tue Jun 11 23:33:03 2002 UTC (17 years, 7 months ago) by sh002i
File size: 2570 byte(s)
started the Webwork database interface.
fun, fun, fun...
-sam

    1 ################################################################################
    2 # WeBWorK mod_perl (c) 1995-2002 WeBWorK Team, Univeristy of Rochester
    3 # $Id$
    4 ################################################################################
    5 
    6 package WeBWorK::DB::Webwork;
    7 
    8 use strict;
    9 use warnings;
   10 use WeBWorK::Set;
   11 use WeBWorK::Problem;
   12 
   13 # there should be a `use' line for each database type
   14 use WeBWorK::DB::GDBM;
   15 
   16 # new($invocant, $courseEnv)
   17 # $invocant - implicitly set by caller
   18 # $courseEnv - an instance of CourseEnvironment
   19 sub new($$) {
   20   my $invocant = shift;
   21   my $class = ref($invocant) || $invocant;
   22   my $courseEnv = shift;
   23   my $dbModule = fullyQualifiedPackageName($courseEnv->{dbInfo}->{wwdb_type});
   24   my $self = {
   25     webwork_file => $courseEnv->{dbInfo}->{wwdb_file},
   26   };
   27   $self->{webwork_db} = $dbModule->new($self->{webwork_file});
   28   bless $self, $class;
   29   return $self;
   30 }
   31 
   32 sub fullyQualifiedPackageName($) {
   33   my $n = shift;
   34   my $package = __PACKAGE__;
   35   $package =~ s/([^:]*)$/$n/;
   36   return $package;
   37 }
   38 
   39 # -----
   40 
   41 sub decode($) {
   42   my $string = shift;
   43   my %hash = $string =~ /(.*?)(?<!\\)=(.*?)(?:(?<!\\)&|$)/g;
   44   $hash{$_} =~ s/\\(.)/$1/ foreach (keys %hash); # unescape anything
   45   return %hash;
   46 }
   47 
   48 sub encode(@) {
   49   my %hash = @_;
   50   my $string;
   51   foreach (keys %hash) {
   52     $hash{$_} =~ s/(=|&)/\\$1/; # escape & and =
   53     $string .= "$_=$hash{$_}&";
   54   }
   55   chop $string; # remove final '&' from string for old code :p
   56   return $string;
   57 }
   58 
   59 # -----
   60 
   61 # hash2set(%hash) - places selected fields from a webwork database record
   62 #                   in a WeBWorK::Set object, which is then returned.
   63 # %hash - a hash representing a database record
   64 sub hash2set(%) {
   65   my %hash = @_;
   66 }
   67 
   68 # set2hash($set) - unpacks a WeBWorK::Set object and returns PART of a hash
   69 #                  suitable for storage in the webwork database.
   70 # $set - a WeBWorK::Set object.
   71 sub set2hash($) {
   72   my $set = shift;
   73 }
   74 
   75 # -----
   76 
   77 # hash@problem($problemNumber, %hash) - places selected fields from a webwork
   78 #                                       database record in a WeBWorK::Problem
   79 #                                       object, which is then returned.
   80 # $problemNumber - the problem number to extract
   81 # %hash - a hash representing a database record
   82 sub hash2problem($%) {
   83   my $problemNumber = shift;
   84   my %hash = @_;
   85 }
   86 
   87 # problem2hash($problem) - unpacks a WeBWorK::Problem object and returns PART
   88 #                          of a hash suitable for storage in the webwork
   89 #                          database.
   90 # $problem - a WeBWorK::Problem object
   91 sub problem2hash($) {
   92   my $problem = shift;
   93 }
   94 
   95 1;

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9