GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages


Manual Reference Pages  -  SAH::EXAMPLES (3)

.ds Aq ’

NAME

Sah::Examples - Examples

CONTENTS

VERSION

This document describes version 0.9.39 of Sah::Examples (from Perl distribution Sah), released on 2015-09-09.

SIMPLE SCHEMAS



 // integer, optional
 "int"

 // required integer
 "int*"

 // same thing
 ["int", {"req": 1}]

 // integer between 1 and 10
 ["int*", {"min": 1, "max": 10}]

 // same thing, the curly brace is optional (unless for advanced stuff)
 ["int*", "min", 1, "max", 10]

 // array of integers between 1 and 10
 ["array*", {"of": [int*, "between": [1, 10]]}]

 // a byte (lets assign it to a new type byte)
 ["int", {"between": [0,255]}]

 // a byte thats divisible by 3
 ["byte", {"div_by": 3}]

 // a byte thats divisible by 3 *and* 5
 ["byte", {div_by&": [3, 5]}]

 // a byte thats divisible by 3 *or* 5
 ["byte", {"div_by|": [3, 5]}]

 // a byte thats *in*divisible by 3
 ["byte", {"!div_by": 3}]



CLAUSE ATTRIBUTES

EXPRESSIONS

FUNCTIONS

MERGING

    Address



 // an address hash (lets assign it to a new type called address)
 ["hash",
     // recognized keys
     "keys", {
         "line1":    ["str*", "max_len": 80],
         "line2":    ["str*", "max_len": 80],
         "city":     ["str*", "max_len": 60],
         "province": ["str*", "max_len": 60],
         "postcode": ["str*", "len_between": [4, 15], "match": "^[\w-]{4,15}$"],
         "country":  ["str*", "len": 2, "match": "^[A-Z][A-Z]$"]
     },
     // keys that must exist in data
     "req_keys",
     ["line1", "city", "province", "postcode", "country"]
  ]

  // a US address, lets base it on address but change postcode to
  // zipcode. also, require country to be set to US
  ["address",
      "merge.subtract.keys", {"postcode": null},
      "merge.normal.keys", {
          "zipcode", ["str*", "len", 5, "match", "^\d{5}$"],
          "country", ["str*", "is", "US"]
      },
      "merge.subtract.req_keys": ["postcode"],
      "merge.add.req_keys":  ["zipcode"]
  ]



HOMEPAGE

Please visit the project’s homepage at <https://metacpan.org/release/Sah>.

SOURCE

Source repository is at <https://github.com/perlancar/perl-Sah>.

BUGS

Please report any bugs or feature requests on the bugtracker website <https://rt.cpan.org/Public/Dist/Display.html?Name=Sah>

When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.

AUTHOR

perlancar <perlancar@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2015 by perlancar@cpan.org.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

Search for    or go to Top of page |  Section 3 |  Main Index


perl v5.20.3 SAH::EXAMPLES (3) 2015-09-08

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with manServer 1.07.