[system] / branches / rel-2-3-dev / webwork2 / lib / WeBWorK / RPC.pm Repository:
ViewVC logotype

View of /branches/rel-2-3-dev/webwork2/lib/WeBWorK/RPC.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4396 - (download) (as text) (annotate)
Thu Aug 24 21:07:52 2006 UTC (6 years, 8 months ago)
File size: 3078 byte(s)
This commit was manufactured by cvs2svn to create branch 'rel-2-3-dev'.

    1 ################################################################################
    2 # WeBWorK Online Homework Delivery System
    3 # Copyright © 2000-2006 The WeBWorK Project, http://openwebwork.sf.net/
    4 # $CVSHeader: webwork2/lib/WeBWorK/RPC.pm,v 1.1 2006/07/28 04:33:25 sh002i Exp $
    5 #
    6 # This program is free software; you can redistribute it and/or modify it under
    7 # the terms of either: (a) the GNU General Public License as published by the
    8 # Free Software Foundation; either version 2, or (at your option) any later
    9 # version, or (b) the "Artistic License" which comes with this package.
   10 #
   11 # This program is distributed in the hope that it will be useful, but WITHOUT
   12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
   13 # FOR A PARTICULAR PURPOSE.  See either the GNU General Public License or the
   14 # Artistic License for more details.
   15 ################################################################################
   16 
   17 package WeBWorK::RPC;
   18 
   19 =head1 NAME
   20 
   21 WeBWorK::RPC - Remote Procedure Calls for WeBWorK.
   22 
   23 =cut
   24 
   25 use strict;
   26 use warnings;
   27 
   28 use Data::Dumper;
   29 use WeBWorK::Authen;
   30 use WeBWorK::Authz;
   31 use WeBWorK::CourseEnvironment;
   32 use WeBWorK::DB;
   33 use WeBWorK::RPC::Request;
   34 use WeBWorK::Utils qw/runtime_use/;
   35 
   36 sub bootstrap {
   37   my ($invocant, %params) = @_;
   38   my $class = ref $invocant || $invocant;
   39   my $self = bless {}, $class;
   40 
   41   my $r = $self->{r} = new WeBWorK::RPC::Request;
   42 
   43   my $ce = eval { new WeBWorK::CourseEnvironment(\%WeBWorK::SeedCE) };
   44   $@ and die "Failed to initialize course environment: $@\n";
   45   $r->ce($ce);
   46 
   47   my $authz = new WeBWorK::Authz($r);
   48   $r->authz($authz);
   49 
   50   my $authen_module = WeBWorK::Authen::class($ce, "user_module");
   51   runtime_use $authen_module;
   52   my $authen = $authen_module->new($r);
   53   $r->authen($authen);
   54 
   55   if (defined $ce->{courseName} and $ce->{courseName} ne "") {
   56     my $db = new WeBWorK::DB($ce->{dbLayout});
   57     $r->db($db);
   58   }
   59 
   60   return $self, %params;
   61 }
   62 
   63 sub hi {
   64   print STDERR __PACKAGE__."::hi(@_) called\n";
   65   return "hello, world";
   66 }
   67 
   68 sub bye {
   69   print STDERR __PACKAGE__."::bye(@_) called\n";
   70   return "goodbye, cruel world";
   71 }
   72 
   73 sub dumper {
   74   print STDERR __PACKAGE__."::dumper(@_) called\n";
   75   return Dumper(\@_);
   76 }
   77 
   78 sub get_course_environment {
   79   my ($self, %params) = bootstrap(@_);
   80   return $self->{r}->ce;
   81 }
   82 
   83 ################################################################################
   84 
   85 package WeBWorK::RPC::CourseManagement;
   86 
   87 use WeBWorK::Utils::CourseManagement;
   88 
   89 sub listCourses {
   90   my ($self) = WeBWorK::RPC::bootstrap(@_);
   91   return WeBWorK::Utils::CourseManagement::listCourses($self->{r}->ce);
   92 }
   93 
   94 sub listArchivedCourses {
   95   my ($self) = WeBWorK::RPC::bootstrap(@_);
   96   return WeBWorK::Utils::CourseManagement::listArchivedCourses($self->{r}->ce);
   97 }
   98 
   99 sub addCourse {
  100   my ($self, %options) = WeBWorK::RPC::bootstrap(@_);
  101   die "missing courseID in \%options" unless defined $options{courseID};
  102   $options{ce} = new WeBWorK::CourseEnvironment({
  103     webwork_dir => $self->{r}->ce->{webwork_dir},
  104     courseName => $options{courseID},
  105   });
  106   return WeBWorK::Utils::CourseManagement::addCourse(%options);
  107 }
  108 
  109 1;

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9