Skip to content

Commit 65502e4

Browse files
committed
refactor: avoided using package.seeall in module definitions.
1 parent a4ca86f commit 65502e4

File tree

3 files changed

+33
-20
lines changed

3 files changed

+33
-20
lines changed

README.markdown

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,14 +145,14 @@ not want to save the data on local file systems.
145145
Author
146146
======
147147

148-
Zhang "agentzh" Yichun (章亦春) <agentzh@gmail.com>
148+
Yichun "agentzh" Zhang (章亦春) <agentzh@gmail.com>
149149

150150
Copyright and License
151151
=====================
152152

153153
This module is licensed under the BSD license.
154154

155-
Copyright (C) 2012, by Zhang "agentzh" Yichun (章亦春) <agentzh@gmail.com>.
155+
Copyright (C) 2012, by Yichun "agentzh" Zhang (章亦春) <agentzh@gmail.com>.
156156

157157
All rights reserved.
158158

lib/resty/upload.lua

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,35 @@
1-
-- Copyright (C) 2012 Zhang "agentzh" Yichun (章亦春)
1+
-- Copyright (C) 2012 Yichun Zhang (agentzh)
22

3-
module("resty.upload", package.seeall)
3+
4+
local sub = string.sub
5+
local req_socket = ngx.req.socket
6+
local insert = table.insert
7+
local len = string.len
8+
local null = ngx.null
9+
local match = string.match
10+
local setmetatable = setmetatable
11+
local error = error
12+
local get_headers = ngx.req.get_headers
13+
14+
15+
module(...)
416

517
_VERSION = '0.03'
618

19+
720
local MAX_LINE_SIZE = 512
821

922
local STATE_BEGIN = 1
1023
local STATE_READING_HEADER = 2
1124
local STATE_READING_BODY = 3
1225
local STATE_EOF = 4
1326

14-
local class = resty.upload
1527

16-
local mt = { __index = class }
28+
local mt = { __index = _M }
1729

18-
local sub = string.sub
19-
local req_socket = ngx.req.socket
20-
local insert = table.insert
21-
local len = string.len
22-
local null = ngx.null
2330
local state_handlers
2431

32+
2533
function new(self, chunk_size)
2634
local boundary = get_boundary()
2735
if not boundary then
@@ -180,7 +188,7 @@ function read_header(self)
180188
return read_body_part(self)
181189
end
182190

183-
local key, value = string.match(line, "([^: \t]+)%s*:%s*(.+)")
191+
local key, value = match(line, "([^: \t]+)%s*:%s*(.+)")
184192
if not key then
185193
return 'header', line
186194
end
@@ -232,12 +240,12 @@ end
232240

233241

234242
function get_boundary()
235-
local header = ngx.var.content_type
243+
local header = get_headers().content_type
236244
if not header then
237245
return nil
238246
end
239247

240-
return string.match(header, ";%s+boundary=(%S+)")
248+
return match(header, ";%s+boundary=(%S+)")
241249
end
242250

243251

@@ -249,9 +257,12 @@ state_handlers = {
249257
}
250258

251259

252-
-- to prevent use of casual module global variables
253-
getmetatable(class).__newindex = function (table, key, val)
254-
error('attempt to write to undeclared variable "' .. key .. '": '
255-
.. debug.traceback())
256-
end
260+
local class_mt = {
261+
-- to prevent use of casual module global variables
262+
__newindex = function (table, key, val)
263+
error('attempt to write to undeclared variable "' .. key .. '"')
264+
end
265+
}
266+
267+
setmetatable(_M, class_mt)
257268

t/sanity.t

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use Cwd qw(cwd);
55

66
repeat_each(2);
77

8-
plan tests => repeat_each() * (2 * blocks());
8+
plan tests => repeat_each() * (3 * blocks());
99

1010
my $pwd = cwd();
1111

@@ -79,4 +79,6 @@ read: ["body","\r\n"]
7979
read: ["part_end"]
8080
read: ["eof"]
8181
read: ["eof"]
82+
--- no_error_log
83+
[error]
8284

0 commit comments

Comments
 (0)