Slide 1

Slide 1 text

Rx

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

SPAM

Slide 4

Slide 4 text

Store Data Spam Storage

Slide 5

Slide 5 text

Store Data Spam Storage pobox web server http

Slide 6

Slide 6 text

{ “cur_page”: 1, “per_page”: 10, “total”: 902, “items”: [ { “id”: 1234, “hdr_subject”: “rock hard math tests”, “discarded_by”: “dnsbl/rbl.wolfram.com” }, ... ], }

Slide 7

Slide 7 text

--- cur_page: 1 per_page: 10 total : 902 items : - id: 1234 hdr_subject : rock hard math tests discarded_by: dnsbl/rbl.wolfram.com ...

Slide 8

Slide 8 text

Store Data Spam Storage pobox web server

Slide 9

Slide 9 text

Store Data Spam Storage ajax web code pobox web server

Slide 10

Slide 10 text

Store Data Spam Storage ajax web code pobox web server your cool app

Slide 11

Slide 11 text

{ “cur_page”: 1, “per_page”: 10, “total”: 902, “items”: [ { “id”: 1234, “hdr_subject”: “rock hard math tests”, “discarded_by”: “dnsbl/rbl.wolfram.com” }, ... ], }

Slide 12

Slide 12 text

XML

Slide 13

Slide 13 text

--- cur_page: 1 per_page: 10 total : 902 items : - id: 1234 hdr_subject : rock hard math tests discarded_by: dnsbl/rbl.wolfram.com ...

Slide 14

Slide 14 text

{ “cur_page”: 1, “per_page”: 10, “total”: 902, “items”: [ { “id”: 1234, “hdr_subject”: “rock hard math tests”, “discarded_by”: “dnsbl/rbl.wolfram.com” }, ... ], }

Slide 15

Slide 15 text

rock hard math tests dnsbl rbl.wolfram.com

Slide 16

Slide 16 text

XSD

Slide 17

Slide 17 text

No content

Slide 18

Slide 18 text

RELAX NG

Slide 19

Slide 19 text

XML isn’t perlish

Slide 20

Slide 20 text

...but schemas are good

Slide 21

Slide 21 text

total : 902 cur_page: 1 per_page: 10 items : - id: 1234 hdr_subject : rock hard math tests discarded_by: dnsbl/rbl.wolfram.com

Slide 22

Slide 22 text

total : 902 cur_page: 1 per_page: 10 items : - id: 1234 hdr_subject : rock hard math tests discarded_by: dnsbl/rbl.wolfram.com type: //rec required: total : //int per_page: //int cur_page: { type: //int, range: { min: 1 } } items : { type: //rec required: { ... }

Slide 23

Slide 23 text

type: //rec required: total : //int per_page: //int cur_page: { type: //int, range: { min: 1 } } items : { type: //rec required: { ... }

Slide 24

Slide 24 text

Perl

Slide 25

Slide 25 text

my $rx = Data::Rx->new; Perl

Slide 26

Slide 26 text

my $rx = Data::Rx->new; Perl

Slide 27

Slide 27 text

my $rx = Data::Rx->new; my $data = { type => ‘//rec’, ... }; Perl

Slide 28

Slide 28 text

my $rx = Data::Rx->new; my $data = { type => ‘//rec’, ... }; Perl

Slide 29

Slide 29 text

my $rx = Data::Rx->new; my $data = { type => ‘//rec’, ... }; my $schema = $rx->make_schema($data); Perl

Slide 30

Slide 30 text

my $rx = Data::Rx->new; my $data = { type => ‘//rec’, ... }; my $schema = $rx->make_schema($data); Perl

Slide 31

Slide 31 text

my $rx = Data::Rx->new; my $data = { type => ‘//rec’, ... }; my $schema = $rx->make_schema($data); if ($schema->check( $input )) { Perl

Slide 32

Slide 32 text

my $rx = Data::Rx->new; my $data = { type => ‘//rec’, ... }; my $schema = $rx->make_schema($data); if ($schema->check( $input )) { ... Perl

Slide 33

Slide 33 text

my $rx = Data::Rx->new; my $data = { type => ‘//rec’, ... }; my $schema = $rx->make_schema($data); if ($schema->check( $input )) { ... } Perl

Slide 34

Slide 34 text

my $rx = Data::Rx->new; my $data = decode_json( $json ); my $schema = $rx->make_schema($data); if ($schema->check( $input )) { ... } Perl

Slide 35

Slide 35 text

var rx = new Rx(); var schema = rx.makeSchema( schemaFromJSON ); if (schema.check(input) { ... } JavaScript

Slide 36

Slide 36 text

rx = Rx.Factory() schema = rx.makeSchema( schemaFromJSON ) if schema.check(input): ... Python

Slide 37

Slide 37 text

rx = Rx.new schema = rx.makeSchema( schemaFromJSON ) if schema.check(input) then ... end Ruby

Slide 38

Slide 38 text

$rx = new Rx(); $schema = $rx.makeSchema( $schemaFromJSON ) if ($schema.check( $input )) { ... } PHP

Slide 39

Slide 39 text

$rx = new Rx(); $schema = $rx.makeSchema( $schemaFromJSON ) if ($schema.check( $input )) { ... } PHP (forgive me)

Slide 40

Slide 40 text

--- type: //str “Isn’t it awfully nice to have a schema?”

Slide 41

Slide 41 text

--- type: //int 42

Slide 42

Slide 42 text

--- type : //int range: { min: 3, max: 18 } 17

Slide 43

Slide 43 text

--- type : //int value: 10 10

Slide 44

Slide 44 text

--- type : //any undef, 1, [ ... ], CGI->new

Slide 45

Slide 45 text

--- type : //any of : - //int - //str - { type: //num, value: 3.141 } “String type, I choose you!”

Slide 46

Slide 46 text

Simple Core Rx Types

Slide 47

Slide 47 text

Simple Core Rx Types •//nil

Slide 48

Slide 48 text

Simple Core Rx Types •//nil •//def

Slide 49

Slide 49 text

Simple Core Rx Types •//nil •//def •//num

Slide 50

Slide 50 text

Simple Core Rx Types •//nil •//def •//num •//int

Slide 51

Slide 51 text

Simple Core Rx Types •//nil •//def •//num •//int •//bool

Slide 52

Slide 52 text

Simple Core Rx Types •//nil •//def •//num •//int •//bool •//str

Slide 53

Slide 53 text

Simple Core Rx Types •//nil •//def •//num •//int •//bool •//str •//one

Slide 54

Slide 54 text

Simple Core Rx Types •//nil •//def •//num •//int •//bool •//str •//one •//fail

Slide 55

Slide 55 text

the //arr type --- type: //arr length: { min: 6, max: 6 } contents: type : //int range: { min: 3, max: 18 } [ 7, 3, 4, 11, 17, 9 ]

Slide 56

Slide 56 text

the //seq type --- type: //seq contents: - //int - //bool - //str [ 10, true, “awesome” ]

Slide 57

Slide 57 text

the //map type --- type : //map values: //int { x => 1, y => 2, z => 3 }

Slide 58

Slide 58 text

the //rec type --- type : //rec required: first: //str last : //str optional: { middle: //str } { first => ‘Rico’, last => ‘Signes’ }

Slide 59

Slide 59 text

the //all type --- type : //all of: - { type: //int, range: { min: 3 } } - { type: //num, range: { max: 18 } } 10

Slide 60

Slide 60 text

//str

Slide 61

Slide 61 text

taguri

Slide 62

Slide 62 text

tag: AUTHORITY , DATE : STRING

Slide 63

Slide 63 text

tag:

Slide 64

Slide 64 text

tag:rjbs.manxome.org

Slide 65

Slide 65 text

tag:rjbs.manxome.org,2008-10-11

Slide 66

Slide 66 text

tag:rjbs.manxome.org,2008-10-11:rx

Slide 67

Slide 67 text

tag:rjbs.manxome.org,2008-10-11:rx/slide

Slide 68

Slide 68 text

No content

Slide 69

Slide 69 text

//str

Slide 70

Slide 70 text

//str

Slide 71

Slide 71 text

//str tag:codesimply.com,2008:rx/core/str

Slide 72

Slide 72 text

--- type: //str

Slide 73

Slide 73 text

--- type: tag:codesimply.com,2008:rx/core/str

Slide 74

Slide 74 text

--- type: tag:codesimply.com,2008:rx/core/str --- type: //str

Slide 75

Slide 75 text

/prefix/rest

Slide 76

Slide 76 text

/prefix/rest (empty) tag:codesimply.com,2008:rx/core/ .meta tag:codesimply.com,2008:rx/meta/ local tag:[email protected]:2009:RxType,

Slide 77

Slide 77 text

/prefix/rest (empty) tag:codesimply.com,2008:rx/core/ .meta tag:codesimply.com,2008:rx/meta/ local tag:[email protected]:2009:RxType,

Slide 78

Slide 78 text

/prefix/rest (empty) tag:codesimply.com,2008:rx/core/ .meta tag:codesimply.com,2008:rx/meta/ local tag:[email protected]:2009:RxType,

Slide 79

Slide 79 text

type: tag:[email protected]:2009:RxType,Account type: /local/Account type: tag:codesimply.com,2008:rx/core/str type: //str type: tag:codesimply.com,2008:rx/meta/str type: /.meta/str

Slide 80

Slide 80 text

Making Types

Slide 81

Slide 81 text

No content

Slide 82

Slide 82 text

•decide what it does

Slide 83

Slide 83 text

•decide what it does •give it a name (tag)

Slide 84

Slide 84 text

•decide what it does •give it a name (tag) •write tests

Slide 85

Slide 85 text

•decide what it does •give it a name (tag) •write tests •implement it

Slide 86

Slide 86 text

•decide what it does •give it a name (tag) •write tests •implement it

Slide 87

Slide 87 text

use Test::More tests => 2; my $rx = Data::Rx->new({ prefix => { moose => ‘tag:rjbs.manxome.org,2008-10-04:rx/moose/’, }, type_plugins => [ ‘Data::Rx::Type::MooseTC’ ] }); my $array_of_int = $rx->make_schema({ type => ‘/moose/tc’, moose_type => ‘ArrayRef[Int]’, }); ok($array_of_int->check([1]), “[1] is an ArrayRef[Int]”); ok(! $array_of_int->check( 1 ), “1 is not an ArrayRef[Int]”); t/moose-types.t

Slide 88

Slide 88 text

•...but then you’d have to rewrite your tests in every language. •We already have Rx running on a bunch of platforms... •...with a shared test suite... •...and we can re-use it.

Slide 89

Slide 89 text

{ “empty” : “[]”, “str-1” : “[\”string\”, 1 ]”, “0” : “[ 0 ]”, “0-1” : “[ 0, 1 ]”, “0-1-1” : “[ 0, 1, 1 ]”, “0-s1-1” : “[ 0, \”1\”, 1 ]”, “0-1-1-2”: “[ 0, 1, 1, 2 ]”, “0-1-1-2”: “[ 0, 1, 1, 2 ]”, “0-str” : “[ 0, \”string\” ]”, “0-str-3”: “[ 0, \”string\”, 3 ]”, “0-str-3-18” : “[ 0, \”string\”, 3, 18 ]”, “0-str-3-T” : “[ 0, \”string\”, 3, true ]”, “0-str-3-T-F” : “[ 0, \”string\”, 3, true, false ]”, “0-str-3-T-str”: “[ 0, \”string\”, 3, true, \”false\” ]”, “0-str-3-T-F-T”: “[ 0, \”string\”, 3, true, false, true ]” } spec/data/arr.json

Slide 90

Slide 90 text

{ “schema”: { “type” : “//arr”, “contents”: { “type”: “//int” }, “length” : { “max”: 3 } }, “pass”: { “arr”: [ “empty”, “0”, “0-1”, “0-1-1” ] }, “fail”: { “arr” : [ “str-1”, “0-s1-1”, “0-1-1-2”, “0-str” ], “bool”: “*”, “null”: “*”, “num” : “*”, “obj” : “*”, “str” : “*” } } spec/schemata/array-3-int.json

Slide 91

Slide 91 text

{ “schema”: { “type” : “tag:rx-foundation.biz/mtfnpy”, “hardness”: 8, “ronpaul” : false }, “pass”: { “mtf”: { “garbled”: true }, “arr”: [ “empty”, “0”, “0-1”, “0-1-1” ] }, “fail”: { “bool”: “*”, “null”: “*”, “num” : “*”, “obj” : “*”, “str” : “*” } } your-schema.json

Slide 92

Slide 92 text

Rx validates data

Slide 93

Slide 93 text

Rx validates data (not strings)

Slide 94

Slide 94 text

Rx validates data (not strings) •Rx isn’t about JSON

Slide 95

Slide 95 text

Rx validates data (not strings) •Rx isn’t about JSON •...or YAML

Slide 96

Slide 96 text

Rx validates data (not strings) •Rx isn’t about JSON •...or YAML •it validates data in memory

Slide 97

Slide 97 text

Rx validates data (not strings) •Rx isn’t about JSON •...or YAML •it validates data in memory •how you transmit it over the wire is your problem

Slide 98

Slide 98 text

Core Types are Portable

Slide 99

Slide 99 text

Core Types are Portable •you won’t see regex in Rx core

Slide 100

Slide 100 text

Core Types are Portable •you won’t see regex in Rx core •because regex don’t work the same everywhere

Slide 101

Slide 101 text

Core Types are Portable •you won’t see regex in Rx core •because regex don’t work the same everywhere •(but there is a PCRE type outside of core!)

Slide 102

Slide 102 text

Too Portable for Perl!

Slide 103

Slide 103 text

Too Portable for Perl! •//int means an integer

Slide 104

Slide 104 text

Too Portable for Perl! •//int means an integer •but in many/most languages, 5 !== “5”

Slide 105

Slide 105 text

Too Portable for Perl! •//int means an integer •but in many/most languages, 5 !== “5” •perl actually can’t distinguish these

Slide 106

Slide 106 text

Too Portable for Perl! •//int means an integer •but in many/most languages, 5 !== “5” •perl actually can’t distinguish these •...that’s why the test suite has “todo”

Slide 107

Slide 107 text

Non-portable Types

Slide 108

Slide 108 text

Non-portable Types type: /perl/obj isa : DateTime

Slide 109

Slide 109 text

Non-portable Types type: /perl/obj isa : DateTime type: /perl/obj does: Throwable

Slide 110

Slide 110 text

Non-portable Types

Slide 111

Slide 111 text

Non-portable Types type : /pcre/str regex: q/\A867-[530]{9}\z/

Slide 112

Slide 112 text

Non-portable Types type : /pcre/str regex: q/\A867-[530]{9}\z/ type: /moose/tc does: ArrayRef[DateTime]

Slide 113

Slide 113 text

Rx Everywhere

Slide 114

Slide 114 text

Rx Everywhere •perl6

Slide 115

Slide 115 text

Rx Everywhere •perl6 •Haskell

Slide 116

Slide 116 text

Rx Everywhere •perl6 •Haskell •C#

Slide 117

Slide 117 text

Rx Everywhere •perl6 •Haskell •C# •ML

Slide 118

Slide 118 text

Any Questions?

Slide 119

Slide 119 text

Thank You!