Using package loader

This commit is contained in:
斟酌 鵬兄 2015-04-18 22:14:36 +08:00
parent 6bfa913c06
commit efd618845c
6 changed files with 47 additions and 9 deletions

View File

@ -1,7 +1,9 @@
var cl = global.botanLoader;
var Dragonfly = global.Dragonfly;
var domain = require('domain');
var FatalError = require( '../errors/FatalError' );
var FatalError = cl.load( "botanss.errors.FatalError" );
// Message is hardcoded to prevent further exceptions occured
// This function must be bug-free
@ -52,7 +54,7 @@ function serverHandle( server, request, response, rHandle )
// Construncor
function AppDomain( handler, port, cluster )
{
var http = require('http');
var http = require( "http" );
var server = http.createServer(
function(req, res) {
serverHandle( server, req, res, handler );

View File

@ -1,5 +1,7 @@
var cl = global.botanLoader;
var Dragonfly = global.Dragonfly;
var Cookie = require( "./Components/Cookie" );
var Cookie = cl.load( "botanss.net.components.Cookie" );
var HTTP = function( req, res )
{

View File

@ -1,9 +1,11 @@
var cl = global.botanLoader;
var Dragonfly = global.Dragonfly;
var util = require( "util" )
, events = require( "events" )
, FatalError = require( '../errors/FatalError.js' )
;
var util = require( "util" );
var events = require( "events" );
var FatalError = cl.load( "botanss.errors.FatalError" )
var MaxRedirect = 10;

View File

@ -1,5 +1,7 @@
var cl = global.botanLoader;
var Dragonfly = global.Dragonfly;
var FatalError = require( '../errors/FatalError.js' );
var FatalError = cl.load( "botanss.errors.FatalError" );
var Framework = function( garden )
{
@ -11,7 +13,7 @@ var Framework = function( garden )
this.requestStr = "";
this.requestObj = {};
var Router = require( "./Router" );
var Router = cl.load( "botanss.net.Router" );
var router = new Router( garden );
router.addRoute( "302", false, "302" );

30
package.js Normal file
View File

@ -0,0 +1,30 @@
// The Package Loader
var fs = require( "fs" );
var rootNS = {
botanss: "./"
};
var Package = function() { };
Package.prototype.rootNS = function( name, path )
{
if( rootNS[ name ] ) return;
rootNS[ name ] = fs.realpathSync( path ) + "/";
};
Package.prototype.load = function( _class )
{
var fSep = _class.indexOf( "." );
var nsdomain = _class.substr( 0, fSep );
_class = _class.substr( fSep + 1 ).replace( /\./g, "/" );
var file = rootNS[ nsdomain ] + _class;
var lClass = require( file );
// TODO: Implements filewatcher
return lClass;
};
global.botanLoader = new Package();