our
$TL
;
1;
sub
_new {
my
$pkg
=
shift
;
my
$this
=
bless
{} =>
$pkg
;
$this
->{form} = {};
$this
->{form_shared} = {};
$this
->{filename} = {};
$this
->{filehandle} = {};
$this
->{fragment} =
undef
;
if
(
@_
== 1) {
if
(!
defined
(
$_
[0])) {
die
"TL#newForm: arg[1] is not defined. (第1引数が指定されていません)\n"
;
}
elsif
(
ref
(
$_
[0]) eq
'HASH'
) {
$this
->set(
@_
);
}
elsif
(
ref
(
$_
[0])) {
die
"TL#newForm: arg[1] is an unacceptable reference. (第1引数が不正なリファレンスです)\n"
;
}
else
{
$this
->setLink(
$_
[0]);
}
}
else
{
$this
->set(
@_
);
}
$this
;
}
sub
_trace {
my
$this
=
shift
;
$this
->{trace} = 1;
$this
;
}
sub
const {
my
$this
=
shift
;
$this
->{const} = 1;
$this
;
}
sub
isConst {
my
$this
=
shift
;
exists
(
$this
->{const});
}
sub
clone {
my
$this
=
shift
;
my
$f
=
$TL
->newForm;
@{
$f
->{form}}{
keys
%{
$this
->{form}}} =
values
%{
$this
->{form}};
@{
$f
->{form_shared}}{
keys
%{
$this
->{form}}} = (1) x
keys
%{
$this
->{form}};
@{
$this
->{form_shared}}{
keys
%{
$this
->{form}}} = (1) x
keys
%{
$this
->{form}};
@{
$f
->{filename}}{
keys
%{
$this
->{filename}}} =
values
%{
$this
->{filename}};
@{
$f
->{filehandle}}{
keys
%{
$this
->{filehandle}}} =
values
%{
$this
->{filehandle}};
$f
->{fragment} =
$this
->{fragment};
$f
;
}
sub
addForm {
my
$this
=
shift
;
my
$form
=
shift
;
if
(
exists
(
$this
->{const})) {
die
__PACKAGE__.
"#addForm: This instance is a const object. (このFormオブジェクトの内容は変更できません)\n"
;
}
if
(
ref
(
$form
) ne
'Tripletail::Form'
) {
die
__PACKAGE__.
"#addForm: args[1] is not instance of Tripletail::Form. (第1引数がFormオブジェクトではありません)\n"
;
}
if
(
$this
->{trace}) {
$TL
->getDebug->_formLog(
type
=>
'addForm'
,
form
=>
$form
,
);
}
my
@addkeys
=
keys
%{
$form
->{form}};
@{
$this
->{form}}{
@addkeys
} =
values
%{
$form
->{form}};
@{
$this
->{form_shared}}{
@addkeys
} = (1) x
@addkeys
;
@{
$form
->{form_shared}}{
@addkeys
} = (1) x
keys
%{
$form
->{form}};
@{
$this
->{filename}}{
keys
%{
$form
->{filename}}} =
values
%{
$form
->{filename}};
@{
$this
->{filehandle}}{
keys
%{
$form
->{filehandle}}} =
values
%{
$form
->{filehandle}};
if
(
defined
$form
->{fragment}) {
$this
->{fragment} =
$form
->{fragment};
}
$this
;
}
sub
getKeys {
my
$this
=
shift
;
keys
%{
$this
->{form}};
}
sub
get {
my
$this
=
shift
;
my
$key
=
shift
;
my
$joinstr
=
shift
||
','
;
if
(
ref
(
$key
)) {
die
__PACKAGE__.
"#get: arg[1] is a reference. (第1引数がリファレンスです)\n"
;
}
if
(
ref
(
$joinstr
)) {
die
__PACKAGE__.
"#get: arg[2] is a reference. (第2引数がリファレンスです)\n"
;
}
if
(!
exists
(
$this
->{form}{
$key
})) {
return
undef
;
}
join
(
$joinstr
, @{
$this
->{form}{
$key
}});
}
sub
getValues {
my
$this
=
shift
;
my
$key
=
shift
;
if
(
ref
(
$key
)) {
die
__PACKAGE__.
"#getValues: arg[1] is a reference. (第1引数がリファレンスです)\n"
;
}
if
(!
exists
(
$this
->{form}{
$key
})) {
return
();
}
@{
$this
->{form}{
$key
}};
}
sub
getSlice {
my
$this
=
shift
;
my
@key
= (
@_
);
my
@res
;
foreach
my
$key
(
@key
) {
if
(
ref
(
$key
)) {
my
$ref
=
ref
(
$key
);
die
__PACKAGE__.
"#getSlice: there is a reference in the arguments. [$key/$ref] (引数にリファレンスが含まれます)\n"
;
}
my
@values
=
$this
->getValues(
$key
);
if
(
scalar
(
@values
) == 1) {
push
(
@res
,
$key
);
push
(
@res
,
$values
[0]);
}
elsif
(
scalar
(
@values
) == 0) {
}
else
{
push
(
@res
,
$key
);
push
(
@res
, \
@values
);
}
}
@res
;
}
sub
getSliceValues {
my
$this
=
shift
;
my
@key
= (
@_
);
my
@res
;
foreach
my
$key
(
@key
) {
if
(
ref
(
$key
)) {
my
$ref
=
ref
(
$key
);
die
__PACKAGE__.
"#getSliceValues: there is a reference in the arguments. [$key/$ref] (引数にリファレンスが含まれます)\n"
;
}
my
@values
=
$this
->getValues(
$key
);
if
(
scalar
(
@values
) == 1) {
push
(
@res
,
$values
[0]);
}
elsif
(
scalar
(
@values
) == 0) {
push
(
@res
,
undef
);
}
else
{
push
(
@res
, \
@values
);
}
}
@res
;
}
sub
lookup {
my
$this
=
shift
;
my
$key
=
shift
;
my
$value
=
shift
;
if
(
ref
(
$key
)) {
die
__PACKAGE__.
"#lookup: arg[1] is a reference. (第1引数がリファレンスです)\n"
;
}
if
(
ref
(
$value
)) {
die
__PACKAGE__.
"#lookup: arg[2] is a reference. (第2引数がリファレンスです)\n"
;
}
if
(!
exists
(
$this
->{form}{
$key
})) {
return
undef
;
}
my
$found
;
for
(
my
$i
= 0;
$i
<= $
if
(
$this
->{form}{
$key
}[
$i
] eq
$value
) {
$found
= 1;
last
;
}
}
if
(!
$found
) {
return
undef
;
}
1;
}
sub
set {
my
$this
=
shift
;
if
(
exists
(
$this
->{const})) {
die
__PACKAGE__.
"#set: This instance is a const object. (このFormオブジェクトの内容は変更できません)\n"
;
}
my
$data
;
if
(
ref
(
$_
[0]) eq
'HASH'
) {
$data
=
shift
;
}
elsif
(!
ref
(
$_
[0])) {
$data
= {
@_
};
}
else
{
my
$ref
=
ref
(
$_
[0]);
die
__PACKAGE__.
"#set: arg[1] is an unacceptable reference. [$ref] (第1引数が不正なリファレンスです)\n"
;
}
if
(
$this
->{trace}) {
$TL
->getDebug->_formLog(
type
=>
'set'
,
data
=>
$data
,
);
}
foreach
my
$key
(
keys
%$data
)
{
my
$val
=
$data
->{
$key
};
if
( !
defined
(
$val
) )
{
delete
$this
->{form}{
$key
};
delete
$this
->{form_shared}{
$key
};
next
;
}
if
( !
ref
(
$val
) )
{
$val
= [
$val
];
}
if
(
ref
(
$val
) ne
'ARRAY'
)
{
my
$ref
=
ref
(
$val
);
die
__PACKAGE__.
"#set: there is an unacceptable reference in the arguments. [$key/$ref] (不正なリファレンスが含まれています)\n"
;
}
if
( !
@$val
)
{
delete
$this
->{form}{
$key
};
delete
$this
->{form_shared}{
$key
};
next
;
}
if
(
my
(
$ref
) =
grep
{
$_
}
map
{
ref
(
$_
)}
@$val
)
{
die
__PACKAGE__.
"#set: there is an unacceptable reference in the arguments. [$key/$ref] (不正なリファレンスが含まれています)\n"
;
}
$this
->{form}{
$key
} = [
@$val
];
delete
$this
->{form_shared}{
$key
};
}
$this
;
}
sub
add {
my
$this
=
shift
;
my
$key
=
shift
;
my
$value
=
shift
;
if
(
exists
(
$this
->{const})) {
die
__PACKAGE__.
"#add: This instance is a const object. (このFormオブジェクトの内容は変更できません)\n"
;
}
if
(
ref
(
$key
)) {
die
__PACKAGE__.
"#add: arg[1] is a reference. (第1引数がリファレンスです)\n"
;
}
if
(
ref
(
$value
)) {
die
__PACKAGE__.
"#add: arg[2] is a reference. (第2引数がリファレンスです)\n"
;
}
if
(
$this
->{trace}) {
$TL
->getDebug->_formLog(
type
=>
'add'
,
key
=>
$key
,
value
=>
$value
,
);
}
if
(
$this
->{form_shared}{
$key
}) {
$this
->{form}{
$key
} = [
@{
$this
->{form}{
$key
}},
$value
,
];
delete
$this
->{form_shared}{
$key
};
}
else
{
push
@{
$this
->{form}{
$key
}},
$value
;
}
$this
;
}
sub
exists
{
my
$this
=
shift
;
my
$key
=
shift
;
if
(
ref
(
$key
)) {
die
__PACKAGE__.
"#exists: arg[1] is a reference. (第1引数がリファレンスです)\n"
;
}
if
(
exists
(
$this
->{form}{
$key
})) {
return
1;
}
undef
;
}
sub
remove {
my
$this
=
shift
;
my
$key
=
shift
;
my
$value
=
shift
;
if
(
exists
(
$this
->{const})) {
die
__PACKAGE__.
"#remove: This instance is a const object. (このFormオブジェクトの内容は変更できません)\n"
;
}
if
(!
defined
(
$key
)) {
die
__PACKAGE__.
"#remove: arg[1] is not defined. (第1引数が指定されていません)\n"
;
}
elsif
(
ref
(
$key
)) {
die
__PACKAGE__.
"#remove: arg[1] is a reference. (第1引数がリファレンスです)\n"
;
}
if
(!
defined
(
$value
)) {
die
__PACKAGE__.
"#remove: arg[2] is not defined. (第2引数が指定されていません)\n"
;
}
elsif
(
ref
(
$value
)) {
die
__PACKAGE__.
"#remove: arg[2] is a reference. (第2引数がリファレンスです)\n"
;
}
if
(!
exists
(
$this
->{form}{
$key
})) {
die
__PACKAGE__.
"#remove: arg[1]: nonexistent key [$key] (指定されたキーは存在しません)\n"
;
}
if
(
$this
->{trace}) {
$TL
->getDebug->_formLog(
type
=>
'remove'
,
key
=>
$key
,
value
=>
$value
,
);
}
for
(
my
$i
= 0;
$i
<= $
if
(
$this
->{form}{
$key
}[
$i
] eq
$value
) {
if
(@{
$this
->{form}{
$key
}} == 1) {
delete
$this
->{form}{
$key
};
delete
$this
->{form_shared}{
$key
};
}
else
{
if
(
$this
->{form_shared}{
$key
}) {
my
@array
= @{
$this
->{form}{
$key
}};
splice
@array
,
$i
, 1;
$this
->{form}{
$key
} = \
@array
;
delete
$this
->{form_shared}{
$key
};
}
else
{
splice
@{
$this
->{form}{
$key
}},
$i
, 1;
}
}
last
;
}
}
$this
;
}
sub
delete
{
my
$this
=
shift
;
my
$key
=
shift
;
if
(
exists
(
$this
->{const})) {
die
__PACKAGE__.
"#delete: This instance is a const object. (このFormオブジェクトの内容は変更できません)\n"
;
}
if
(
ref
(
$key
)) {
die
__PACKAGE__.
"#delete: arg[1] is a reference. (第1引数がリファレンスです)\n"
;
}
if
(
$this
->{trace}) {
$TL
->getDebug->_formLog(
type
=>
'delete'
,
key
=>
$key
,
);
}
if
(!
exists
(
$this
->{form}{
$key
})) {
return
$this
;
}
delete
$this
->{form}{
$key
};
delete
$this
->{form_shared}{
$key
};
$this
;
}
sub
getFile {
my
$this
=
shift
;
my
$key
=
shift
;
my
$charset_from
=
shift
;
my
$charset_to
=
shift
;
if
(
ref
$key
) {
die
__PACKAGE__.
"#getFile: arg[1] is a reference. (第1引数がリファレンスです)\n"
;
}
if
(
defined
(
my
$fh_in
=
$this
->{filehandle}{
$key
})) {
if
(
defined
$charset_from
) {
$charset_to
||=
'UTF-8'
;
my
$fh_out
= IO::File->new_tmpfile;
seek
$fh_in
, 0, 0;
local
$/ =
"\n"
;
while
(
defined
(
my
$line
= <
$fh_in
>)) {
print
{
$fh_out
}
$TL
->charconv(
$line
,
$charset_from
,
$charset_to
);
}
seek
$fh_out
, 0, 0;
return
$fh_out
;
}
else
{
return
$fh_in
;
}
}
else
{
return
undef
;
}
}
sub
existsFile {
my
$this
=
shift
;
my
$key
=
shift
;
if
(
ref
(
$key
)) {
die
__PACKAGE__.
"#existsFile: arg[1] is a reference. (第1引数がリファレンスです)\n"
;
}
if
(
defined
(
$this
->{filehandle}{
$key
}) )
{
return
1;
}
undef
;
}
sub
isUploaded {
my
$this
=
shift
;
my
$key
=
shift
;
if
(
ref
(
$key
)) {
die
__PACKAGE__.
"#isUploaded: arg[1] is a reference. (第1引数がリファレンスです)\n"
;
}
if
(
defined
(
$this
->{filename}{
$key
}) &&
$this
->{filename}{
$key
} ne
''
)
{
return
1;
}
undef
;
}
sub
setFile {
my
$this
=
shift
;
my
$key
=
shift
;
my
$value
=
shift
;
if
(
exists
(
$this
->{const})) {
die
__PACKAGE__.
"#setFile: This instance is a const object. (このFormオブジェクトの内容は変更できません)\n"
;
}
if
(
ref
(
$key
)) {
die
__PACKAGE__.
"#setFile: arg[1] is a reference. (第1引数がリファレンスです)\n"
;
}
if
(
$this
->{trace}) {
$TL
->getDebug->_formLog(
type
=>
'setFile'
,
key
=>
$key
,
value
=>
defined
$value
?
"$value"
:
'[undef]'
,
);
}
if
(!
defined
(
$value
)) {
delete
$this
->{filehandle}{
$key
};
}
elsif
(!
ref
(
$value
)) {
die
__PACKAGE__.
"#setFile: arg[2] is not a reference. (第2引数がリファレンスではありません)\n"
;
}
else
{
$this
->{filehandle}{
$key
} =
$value
;
}
$this
;
}
sub
getFileKeys {
my
$this
=
shift
;
keys
%{
$this
->{filehandle}};
}
sub
getFileName {
my
$this
=
shift
;
my
$key
=
shift
;
if
(
ref
(
$key
)) {
die
__PACKAGE__.
"#getFileName: arg[1] is a reference. (第1引数がリファレンスです)\n"
;
}
my
$filename
=
$this
->{filename}{
$key
};
if
(
defined
(
$filename
) && !
$TL
->INI->get(
TL
=>
compat_form_getfilename_returns_fullpath
=> 0) )
{
$filename
=~ s{.*[/\\]}{};
}
$filename
;
}
sub
getFullFileName {
my
$this
=
shift
;
my
$key
=
shift
;
if
(
ref
(
$key
)) {
die
__PACKAGE__.
"#getFullFileName: arg[1] is a reference. (第1引数がリファレンスです)\n"
;
}
$this
->{filename}{
$key
};
}
sub
setFileName {
my
$this
=
shift
;
my
$key
=
shift
;
my
$value
=
shift
;
if
(
exists
(
$this
->{const})) {
die
__PACKAGE__.
"#setFileName: This instance is a const object. (このFormオブジェクトの内容は変更できません)\n"
;
}
if
(
ref
(
$key
)) {
die
__PACKAGE__.
"#setFileName: arg[1] is a reference. (第1引数がリファレンスです)\n"
;
}
if
(
ref
(
$value
)) {
die
__PACKAGE__.
"#setFileName: arg[2] is a reference. (第2引数がリファレンスです)\n"
;
}
if
(
$this
->{trace}) {
$TL
->getDebug->_formLog(
type
=>
'setFileName'
,
key
=>
$key
,
value
=>
defined
$value
?
$value
:
'[undef]'
,
);
}
if
(
defined
(
$value
)) {
$this
->{filename}{
$key
} =
$value
;
}
else
{
delete
$this
->{filename}{
$key
};
}
$this
;
}
sub
setLink {
my
$this
=
shift
;
my
$url
=
shift
;
if
(
$this
->{const}) {
die
__PACKAGE__.
"#setLink: This instance is a const object. (このFormオブジェクトの内容は変更できません)\n"
;
}
if
(!
defined
(
$url
)) {
die
__PACKAGE__.
"#setLink: arg[1] is not defined. (第1引数が指定されていません)\n"
;
}
if
(
ref
(
$url
)) {
die
__PACKAGE__.
"#setLink: arg[1] is a reference. (第1引数がリファレンスです)\n"
;
}
if
(
$this
->{trace}) {
$TL
->getDebug->_formLog(
type
=>
'setLink'
,
value
=>
$url
,
);
}
local
(
$this
->{trace}) =
undef
;
foreach
my
$key
(
$this
->getKeys) {
$this
->
delete
(
$key
);
}
$this
->addLink(
$url
);
$this
;
}
sub
addLink {
my
$this
=
shift
;
my
$url
=
shift
;
if
(
$this
->{const}) {
die
__PACKAGE__.
"#addLink: This instance is a const object. (このFormオブジェクトの内容は変更できません)\n"
;
}
if
(!
defined
(
$url
)) {
die
__PACKAGE__.
"#addLink: arg[1] is not defined. (第1引数が指定されていません)\n"
;
}
if
(
ref
(
$url
)) {
die
__PACKAGE__.
"#addLink: arg[1] is a reference. (第1引数がリファレンスです)\n"
;
}
if
(
$this
->{trace}) {
$TL
->getDebug->_formLog(
type
=>
'addLink'
,
value
=>
$url
,
);
}
local
(
$this
->{trace}) =
undef
;
my
(
$form
,
$fragment
) =
$TL
->_decodeFromURL(
$url
);
$this
->addForm(
$form
);
$this
->setFragment(
$fragment
);
$this
;
}
sub
setFragment {
my
$this
=
shift
;
my
$fragment
=
shift
;
if
(
$this
->{const}) {
die
__PACKAGE__.
"#setFragment: This instance is a const object. (このFormオブジェクトの内容は変更できません)\n"
;
}
if
(
ref
(
$fragment
)) {
die
__PACKAGE__.
"#setFragment: arg[1] is a reference. (第1引数がリファレンスです)\n"
;
}
if
(
$this
->{trace}) {
$TL
->getDebug->_formLog(
type
=>
'setFragment'
,
value
=>
$fragment
);
}
$this
->{fragment} =
$fragment
;
$this
;
}
sub
getFragment {
my
$this
=
shift
;
$this
->{fragment};
}
sub
toLink {
my
$this
=
shift
;
my
$base
=
shift
;
if
(
ref
(
$base
)) {
die
__PACKAGE__.
"#toLink: arg[1] is a reference. (第1引数がリファレンスです)\n"
;
}
if
(!
defined
(
$base
)) {
my
$uri
=
$ENV
{
'REQUEST_URI'
}||
''
;
$uri
=~ s/\?.*$//;
if
(
$uri
=~ m,/([^/]+)$,) {
$base
= $1;
}
else
{
$base
=
'./'
;
}
}
my
$flag
= 0;
foreach
my
$key
(
sort
$this
->getKeys) {
foreach
my
$value
(
sort
$this
->getValues(
$key
)) {
if
(
$flag
== 0) {
$base
.=
'?'
;
$flag
= 1;
}
else
{
$base
.=
'&'
;
}
$base
.=
$TL
->encodeURL(
$key
) .
'='
.
$TL
->encodeURL(
$value
);
}
}
if
(
$flag
== 0) {
$base
.=
'?'
;
}
else
{
$base
.=
'&'
;
}
$base
.=
'INT=1'
;
if
(
defined
(
$this
->{fragment})) {
$base
.=
'#'
.
$TL
->encodeURL(
$this
->{fragment});
}
$base
;
}
sub
toExtLink {
my
$this
=
shift
;
my
$base
=
shift
;
my
$code
=
shift
;
if
(!
defined
(
$code
)) {
$code
=
'UTF-8'
;
}
if
(
ref
(
$base
)) {
die
__PACKAGE__.
"#toExtLink: arg[1] is a reference. (第1引数がリファレンスです)\n"
;
}
if
(!
defined
(
$base
)) {
my
$uri
=
$ENV
{
'REQUEST_URI'
}||
''
;
$uri
=~ s/\?.*$//;
if
(
$uri
=~ m,/([^/]+)$,) {
$base
= $1;
}
else
{
$base
=
'./'
;
}
}
my
$flag
= 0;
foreach
my
$key
(
sort
$this
->getKeys) {
foreach
my
$value
(
sort
$this
->getValues(
$key
)) {
if
(
$flag
== 0) {
$base
.=
'?'
;
$flag
= 1;
}
else
{
$base
.=
'&'
;
}
$base
.=
$TL
->encodeURL(
$TL
->charconv(
$key
,
'UTF-8'
=>
$code
))
.
'='
.
$TL
->encodeURL(
$TL
->charconv(
$value
,
'UTF-8'
=>
$code
));
}
}
if
(
defined
(
$this
->{fragment})) {
$base
.=
'#'
.
$TL
->encodeURL(
$TL
->charconv(
$this
->{fragment},
'UTF-8'
=>
$code
));
}
$base
;
}
sub
haveSessionCheck {
my
$this
=
shift
;
my
$sessiongroup
=
shift
;
my
$issecure
=
shift
;
if
(
ref
(
$sessiongroup
) && Tripletail::_isa(
$sessiongroup
,
'Tripletail::Session'
) )
{
$sessiongroup
=
$sessiongroup
->{group};
}
if
(!
defined
(
$sessiongroup
)) {
die
__PACKAGE__.
"#haveSessionCheck: arg[1] is not defined. (第1引数が指定されていません)\n"
;
}
my
$session
=
$TL
->getSession(
$sessiongroup
);
if
(!
defined
(
$session
)) {
die
__PACKAGE__.
"#haveSessionCheck: session group ($sessiongroup) does not exist. (セッショングループ${sessiongroup}がありません)\n"
;
}
my
(
$key
,
$value
,
$err
) =
$session
->_createSessionCheck(
$issecure
);
if
(
$err
)
{
die
__PACKAGE__.
"#haveSessionCheck: $err"
;
}
if
(
$this
->get(
$key
) eq
$value
) {
return
1;
}
else
{
return
undef
;
}
}
sub
toHash {
return
shift
->{form};
}