1Gtk2::Ex::FormFactory::URsuelresC(o3n)tributed Perl DocuGmtekn2t:a:tEixo:n:FormFactory::Rules(3)
2
3
4

NAME

6       Gtk2::Ex::FormFactory::Rules - Rule checking in a FormFactory framework
7

SYNOPSIS

9         Gtk2::Ex::FormFactory::Rules->new (
10           rules          => Hashref of rules and their implemenation CODEREF's,
11           rules_messages => Hashref of the rules' error messages,
12           message_format => Format of the "Invalid rules" message thrown
13                             on the GUI,
14         );
15

DESCRIPTION

17       This class implements rule checking in a Gtk2::Ex::FormFactory
18       framework.  Each widget can have on or more rules (combined with the
19       locical and operator, except for the special "or-empty" rule described
20       beyond) which are checked against the widget's value when the user
21       changes it. This way you can prevent the user from entering illegal
22       data at a high level.
23
24       Once the user entered illegal data, the old (legal) value is restored
25       and a corresponding error dialog pops up.
26

OBJECT HIERARCHY

28         Gtk2::Ex::FormFactory::Rules
29

ATTRIBUTES

31       Attributes are handled through the common get_ATTR(), set_ATTR() style
32       accessors.
33
34       rules = HASHREF [optional]
35           This is a hash of user specified rules. A rule has a name (the hash
36           key) and a CODREF (the hash value) which implements the rule. The
37           CODEREF has the following prototype:
38
39             $error = &$CODEREF ($value)
40
41           If $value doesn't match the rule, $error is the corresponding error
42           message. $error is undef, if $value is Ok.
43
44       rules_messages = HASHREF [optional]
45           This is a hash of the error messages of the user specified rules.
46           A message should read read as follows:
47
48             {field} is an odd value.
49
50           When presented to the user, the {field} place holder is replaced
51           with the label of the widget in question.
52
53       message_format = SCALAR [optional]
54           This is the format string for the error message which is displayed
55           to the user. The default is:
56
57             Data entered is invalid.\n\n[MESSAGES]\nOld value restored.
58
59           where [MESSAGES] is replaced with the actual list of error
60           messages.
61

BUILTIN RULES

63       This is a verbatim snapshot of the builtin rules and rules_messages
64       hashes. Please take a look at Gtk2::Ex::FormFactory::Rules' source code
65       for a recent list of builtin rules:
66
67         my %RULES = (
68           "empty"                     => sub { $_[0] eq ''                    },
69           "not-empty"                 => sub { $_[0] ne ''                    },
70
71           "alphanumeric"              => sub { $_[0] =~ /^\w+$/               },
72           "identifier"                => sub { $_[0] =~ /^[a-z_]\w*$/i        },
73           "no-whitespace"             => sub { $_[0] !~ /\s/                  },
74
75           "zero"                      => sub { $_[0] =~ /^0(\.0*)?$/          },
76           "not-zero"                  => sub { $_[0] !~ /^0(\.0*)?$/          },
77
78           "integer"                   => sub { $_[0] =~ /^[+-]?\d+$/          },
79           "positive-integer"          => sub { $_[0] =~ /^[+]?\d+$/           },
80           "negative-integer"          => sub { $_[0] =~ /^-\d+$/              },
81
82           "float"                     => sub { $_[0] =~ /^[+-]?\d+(\.\d+)?$/  },
83           "positive-float"            => sub { $_[0] =~ /^\+?\d+(\.\d+)?$/    },
84           "negative-float"            => sub { $_[0] =~ /^-\d+(\.\d+)?$/      },
85
86           "odd"                       => sub {   $_[0] % 2                    },
87           "even"                      => sub { !($_[0] % 2)                   },
88
89           "file-executable"           => sub { (!-d $_[0] && -x $_[0])        },
90           "file-writable"             => sub { (!-d $_[0] && -w $_[0])        },
91           "file-readable"             => sub { (!-d $_[0] && -r $_[0])        },
92
93           "dir-writable"              => sub { (-d $_[0] && -w $_[0])         },
94           "dir-readable"              => sub { (-d $_[0] && -r $_[0])         },
95
96           "parent-dir-writable"       => sub { -w dirname($_[0])              },
97           "parent-dir-readable"       => sub { -r dirname($_[0])              },
98
99           "executable-command"        => "_rule_result",
100         );
101
102         my %RULES_MESSAGES = (
103           "empty"                     => "{field} is not empty.",
104           "not-empty"                 => "{field} is empty.",
105
106           "alphanumeric"              => "{field} is not alphanumeric.",
107           "identifier"                => "{field} is no identifier.",
108           "no-whitespace"             => "{field} contains whitespace.",
109
110           "zero"                      => "{field} is not zero",
111           "not-zero"                  => "{field} is zero",
112
113           "integer"                   => "{field} is no integer.",
114           "positive-integer"          => "{field} is no positive integer.",
115           "negative-integer"          => "{field} is no negative integer.",
116
117           "float"                     => "{field} is no float.",
118           "positive-float"            => "{field} is no positive float.",
119           "negative-float"            => "{field} is no negativ float.",
120
121           "odd"                       => "{field} is not odd.",
122           "even"                      => "{field} is not even.",
123
124           "file-executable"           => "{field} is no file and/or not executable.",
125           "file-writable"             => "{field} is no file and/or not writable.",
126           "file-readable"             => "{field} is no file and/or not readable.",
127
128           "dir-writable"              => "{field} is no directory and/or not writable.",
129           "dir-readable"              => "{field} is no directory and/or not readable.",
130
131           "parent-dir-writable"       => "{field} has no writable parent directory.",
132           "parent-dir-readable"       => "{field} has no readable parent directory.",
133         );
134
135   Special "or-empty" rule
136       There is a special rule called "or-empty". If this rule occurs
137       everywhere in the list of rules and the actual value is empty, rule
138       checking quits immediately with a positive result, discarding error
139       states from earlier rules.
140
141       Example: [ "positive-integer", "or-empty" ]
142
143       All rules are combined with "and", which is usually sufficient, but
144       without this special "or-empty" case the common case optionally empty
145       fields can't be done.
146

AUTHORS

148        Jörn Reder <joern at zyn dot de>
149
151       Copyright 2004-2006 by Jörn Reder.
152
153       This library is free software; you can redistribute it and/or modify it
154       under the terms of the GNU Library General Public License as published
155       by the Free Software Foundation; either version 2.1 of the License, or
156       (at your option) any later version.
157
158       This library is distributed in the hope that it will be useful, but
159       WITHOUT ANY WARRANTY; without even the implied warranty of
160       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
161       Library General Public License for more details.
162
163       You should have received a copy of the GNU Library General Public
164       License along with this library; if not, write to the Free Software
165       Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307
166       USA.
167

POD ERRORS

169       Hey! The above document had some coding errors, which are explained
170       below:
171
172       Around line 349:
173           Non-ASCII character seen before =encoding in 'Jörn'. Assuming UTF-8
174
175
176
177perl v5.28.1                      2006-02-27   Gtk2::Ex::FormFactory::Rules(3)
Impressum