<commit_before>-- perf
local pairs = pairs
local require = require
local setmetatable = setmetatable
local function tappend(t, v) t[#t+1] = v end
local function buildconf(config)
    local sys_conf = require('vanilla.v.config')
    if config ~= nil then
        for k,v in pairs(config) do sys_conf[k] = v end
    end
    return sys_conf
end

local Application = {}

function Application:new(ngx, config)
    self.ngx = ngx
    self.config = buildconf(config)
    local ok, dispatcher_or_error = pcall(function() return require('vanilla.v.dispatcher'):new(self) end)
    if ok then
        dispatcher = dispatcher_or_error
    else
        self:raise_syserror(dispatcher_or_error)
    end
    local instance = {
        run = self.run,
        bootstrap = self.bootstrap,
        dispatcher = dispatcher
    }
    setmetatable(instance, {__index = self})
    return instance
end

function Application:bootstrap()
    local ok, bootstrap_or_error = pcall(function() return require('application.bootstrap'):new(self.dispatcher) end)
    if ok then
        bootstrap = bootstrap_or_error
    else
        self:raise_syserror(bootstrap_or_error)
    end

    local ok, bootstarp_or_error = pcall(function() return bootstrap:bootstrap() end)
    if ok == false then
        self:raise_syserror(bootstarp_or_error)
    end
    
    return self
end

function Application:run()
    local ok, status_or_error = pcall(function() return self.dispatcher:dispatch() end)
    if ok == false then
        self:raise_syserror(status_or_error)
    end
end

function Application:raise_syserror(err)
    ngx.say(pps(err))
    ngx.eof()
end

return Application<commit_msg>create lpcall a instance method<commit_after>-- perf
local pairs = pairs
local pcall = pcall
local require = require
local setmetatable = setmetatable
local function tappend(t, v) t[#t+1] = v end
local function buildconf(config)
    local sys_conf = require('vanilla.v.config')
    if config ~= nil then
        for k,v in pairs(config) do sys_conf[k] = v end
    end
    return sys_conf
end

local Application = {}

function Application:lpcall( ... )
    local ok, rs_or_error = pcall( ... )
    if ok then
        return rs_or_error
    else
        self:raise_syserror(rs_or_error)
    end
end

function Application:new(ngx, config)
    self.ngx = ngx
    self.config = buildconf(config)
    local instance = {
        run = self.run,
        bootstrap = self.bootstrap,
        dispatcher = self:lpcall(function() return require('vanilla.v.dispatcher'):new(self) end)
    }
    setmetatable(instance, {__index = self})
    return instance
end

function Application:bootstrap()
    bootstrap = self:lpcall(function() return require('application.bootstrap'):new(self.dispatcher) end)
    self:lpcall(function() return bootstrap:bootstrap() end)
    
    return self
end

function Application:run()
    self:lpcall(function() return self.dispatcher:dispatch() end)
end

function Application:raise_syserror(err)
    ngx.say(pps(err))
    ngx.eof()
end

return Application
{'fraction_non_alphanumeric': 0.09526959973536223, 'fraction_numerical': 0.0006615944426066821, 'mean_word_length': 3.473372781065089, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2456336', 'n_tokens_mistral': 945, 'n_tokens_neox': 928, 'n_words': 249}