Changeset 2539
- Timestamp:
- Nov 30, 2004, 12:27:21 PM (22 years ago)
- File:
-
- 1 edited
-
trunk/doc/misc/perlCodeConventions.tex (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/doc/misc/perlCodeConventions.tex
r2484 r2539 1 %%% $Id: perlCodeConventions.tex,v 1.3 8 2004-11-25 03:39:17jhoblitt Exp $1 %%% $Id: perlCodeConventions.tex,v 1.39 2004-11-30 22:27:21 jhoblitt Exp $ 2 2 \documentclass[panstarrs]{panstarrs} 3 3 … … 1180 1180 \end{verbatim} 1181 1181 1182 \subsubsection{Subroutine Prototypes} 1183 1184 Do not use subroutine prototypes. If you need to validate subroutine 1185 parameters see \code{Params::Validate} (\S\ref{Params::Validate}). 1186 1187 \begin{verbatim} 1188 sub myopen (*;$) # AVOID! 1189 \end{verbatim} 1190 1191 1182 1192 %------------------------------------------------------------------------------ 1183 1193 \appendix %Begin Appendices … … 1211 1221 \verbatiminput{.perltidyrc} 1212 1222 1223 \section{Params::Validate} 1224 \label{Params::Validate} 1225 1226 \code{Params::Validate}\footnote{Params::Validate - 1227 http://search.cpan.org/~drolsky/Params-Validate/} is a Perl module that allows 1228 you to perform rigorous subroutine parameter validation. It is highly 1229 configurable and validation may be deactivated at runtime 1230 1231 The basic premise is that a validation specification is passed to one of 1232 several ``validating'' subroutines along with the parameters the subroutine was 1233 called with. 1234 1235 An example \code{Params::Validate} named parameters validation spec taken from 1236 the \code{DateTime} module. 1237 1238 \begin{verbatim} 1239 my $BasicValidate = 1240 { year => { type => SCALAR }, 1241 month => { type => SCALAR, default => 1, 1242 callbacks => 1243 { 'is between 1 and 12' => 1244 sub { $_[0] >= 1 && $_[0] <= 12 } 1245 }, 1246 }, 1247 day => { type => SCALAR, default => 1, 1248 callbacks => 1249 { 'is a possible valid day of month' => 1250 sub { $_[0] >= 1 && $_[0] <= 31 } 1251 }, 1252 }, 1253 hour => { type => SCALAR, default => 0, 1254 callbacks => 1255 { 'is between 0 and 23' => 1256 sub { $_[0] >= 0 && $_[0] <= 23 }, 1257 }, 1258 }, 1259 minute => { type => SCALAR, default => 0, 1260 callbacks => 1261 { 'is between 0 and 59' => 1262 sub { $_[0] >= 0 && $_[0] <= 59 }, 1263 }, 1264 }, 1265 second => { type => SCALAR, default => 0, 1266 callbacks => 1267 { 'is between 0 and 61' => 1268 sub { $_[0] >= 0 && $_[0] <= 61 }, 1269 }, 1270 }, 1271 nanosecond => { type => SCALAR, default => 0, 1272 callbacks => 1273 { 'cannot be negative' => 1274 sub { $_[0] >= 0 }, 1275 } 1276 }, 1277 locale => { type => SCALAR | OBJECT, 1278 default => undef }, 1279 language => { type => SCALAR | OBJECT, 1280 optional => 1 }, 1281 }; 1282 \end{verbatim} 1283 1284 An example of how a validation spec is used in the \code{DateTime} module. 1285 1286 \begin{verbatim} 1287 use Params::Validate qw( validate validate_pos SCALAR BOOLEAN HASHREF OBJECT ); 1288 . 1289 . 1290 1291 sub new 1292 { 1293 my $class = shift; 1294 my %p = validate( @_, $NewValidate ); 1295 . 1296 . 1297 \end{verbatim} 1298 1299 Please see the \code{Params::Validate} Pod\footnote{Params::Validate Pod - 1300 http://search.cpan.org/~drolsky/Params-Validate/lib/Params/Validate.pm} for 1301 further details. 1302 1213 1303 \bibliographystyle{plain} 1214 1304 \bibliography{panstarrs}
Note:
See TracChangeset
for help on using the changeset viewer.
