package Sah::Examples; # just to make PodWeaver happy

our $VERSION = '0.9.14'; # VERSION

1;
# ABSTRACT: Examples


__END__
=pod

=head1 NAME

Sah::Examples - Examples

=head1 VERSION

version 0.9.14

=head1 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 (let's assign it to a new type 'byte')
 ["int", {"between": [0,255]}]

 // a byte that's divisible by 3
 ["byte", {"div_by": 3}]

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

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

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

=head1 CLAUSE ATTRIBUTES

=head1 EXPRESSIONS

=head1 FUNCTIONS

=head1 MERGING

=head2 Address

 // an address hash (let's 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, let's 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"]
  ]

=head1 AUTHOR

Steven Haryanto <stevenharyanto@gmail.com>

=head1 COPYRIGHT AND LICENSE

This software is copyright (c) 2012 by Steven Haryanto.

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

=cut

