SlideShare uma empresa Scribd logo
1 de 42
DATA::VERIFIER
                      &
MESSAGE::STACK
Invigorating The Forgotten Bits Of Your Web App
CORY G WATSON: GPHAT

•   Magazines.com: Group Director, Development

•   Cold Hard Code: Creative Director

•   Contributor and Color Commentator on various projects.
BIASES: I HAVE THEM

•   I’m a closet designer

•   I hate All-In-One Form handlers

•   Messaging & Validation are not sexy
VALIDATION: PRIMER

•   Client side is advancing.

•   It won’t replace server side.*

•   Duplication of effort.
VALIDATION:
     DATA::FORMVALIDATOR

•   8+ years old

•   Big, Complex
DATA::VERIFIER
D:V – FEATURES
•   Reusable constraints and coercion

•   Required, optional & dependents

•   Length checking

•   Global and per-field filters
MOOSE
WHY MOOSE?
•   Simplicity

•   Type Constraints

•   Coercion

•   Serialization
GETTING STARTED
my $dv = Data::Verifier->new(…);
my $results = $dv->verify(%params);
if($results->success) {
    # o/
} else {
    # :(
}
PROFILE
              profile => %fields
•   Simple HashRef

•   A key for each field

•   Opposite of D:FV, fields before required/optional
FIELD KEYS
•   coerce            •   min_length

•   coercion          •   post_check

•   dependent         •   required

•   filters            •   type

•   max_length
EASY ONES
•   required: Optional? Then it’s not required!

•   max_length => $x

•   min_length => $y

•   type => $moose_type
EXAMPLE
filters => [ qw(trim) ],
profile => {
  email => {
    min_length => 5
    type => EmailAddress,
    required => 1
  }
}
COERCE

•   Same as Moose’s coerce flag

•   true tells D:V to use Moose coercions

•   Occludes coercion
COERCION

•   Allows one-off coercions

•   Does not define a global Moose coercion

•   Saves cluttering your ::Types with coercions
COERCION (CONT)
coercion => Data::Verifier::coercion(
  from => ‘Int’,
  via => sub {
    DateTime->from_epoch(epoch => $_)
  }
)
DEPENDENT


•   Field A depends on Field B

•   More? Field A can depend on an entire profile.

•   Creates a new D:V, verifies it, merges it with this one.
DEPENDENT
password => {
  dependent => {
    password2 => {
      required => 1
    }
  }
}
FILTERS
              filters => [ qw(trim) ]



•   Comes with some built-ins.

•   Also allows CodeRefs

•   Global and per-field
POST_CHECK


•   Checked at end of verification.

•   Accepts a CodeRef

•   Given Results object as argument.

•   $password1 eq $password2 scenarios
POST_CHECK (CONT)
post_check => sub {
  my ($r) = @_;
  return $r->get_value(‘pass1’)
   eq $r->get_value(‘pass2’);
}
RESULT METHODS
•   get_original_value # unmodified

•   get_value # filters, coercions

•   is_missing, is_valid

•   More!
SERIALIZATION
•   MooseX::Storage

•   caveat: value isn’t serialized, arbitrary type

•   use get_original_value

•   validity and missing is retained
MESS-AGING

•   Error variable

•   Error ArrayRef

•   Error plugin?
MESSAGING

•   Context

•   Level

•   Localization
MESSAGE
•   id: Localization

•   level: ‘error’, ‘info’

•   params: [ ‘gphat@coldhardcode’ ]

•   scope: ‘login_form’

•   subject: ‘email’

•   text: ‘Invalid email address.’
MESSAGE::STACK
MESSAGE::STACK

•   List of messages

•   Order is retained

•   Convenience methods

•   Many methods return sub-Stacks
ADD A MESSAGE

$stack->add(
 id     => ‘invalid_email’,
 scope => ‘login_form’,
 subject=> ‘email’,
 level => ‘error’
);
BEING INFORMED

•   count

•   id, level, scope, subject

•   has_* (boolean)

•   for_* (subset Message::Stack)
Error Message!
                     Error Message!




         Line Item 1             Line Item 1
       Delivery Options          Gift Options




         Line Item 2             Line Item 2
       Delivery Options          Gift Options




CRAPPY FORM: WHERE ARE
Error Message!

      Line Item 1       Line Item 1
    Delivery Options    Gift Options




                       Error Message!

      Line Item 2       Line Item 2
    Delivery Options    Gift Options




GOOD FORM: PRECISE
METHODS

•   Errors: for_level(‘error’);

•   Sub-Form: for_scope(‘line-item1’);

•   Specific field: has_subject(‘email’);

•   Cat: c.loc(message.id, message.params)
HINTS

•   Templates can get messy.

•   Works well with macros.

•   Use a lot or a little.

•   foreach($stack->messages)
DATA::VERIFIER
      +
MESSAGE::STACK
DATA::MANAGER
DATA::MANAGER
my $dm = Data::Manager->new;

my $v = Data::Verifier->new...;

$dm->set_verifier(‘foo’, $v);

$dm->verify(‘foo’, { ... });

my $res => $dm->get_results(‘foo’);
DATA::MANAGER (CONT)

•   A single Message::Stack

•   Multiple Data::Verifier objects (scopes)

•   success

•   messages_for_scope
SUMMARY
•   Simplified validation

•   Reusable types

•   Serialization for redirects.

•   Messaging is important.

•   Context, context, context!
QUESTIONS?
COLOPHON
•   Titling: Tungsten 72pt, Hoefler & Frere-Jones

•   Body: Hoefler Text 38pt, Hoefler & Frere-Jones

•   Diagrams: OmniGraffle, The Omni Group

•   Presentation: Keynote ’09, Apple, Inc

•   Theme: Modified “Showroom”

Mais conteúdo relacionado

Mais procurados

JavaScript Fundamentals & JQuery
JavaScript Fundamentals & JQueryJavaScript Fundamentals & JQuery
JavaScript Fundamentals & JQuery
Jamshid Hashimi
 
fuser interface-development-using-jquery
fuser interface-development-using-jqueryfuser interface-development-using-jquery
fuser interface-development-using-jquery
Kostas Mavridis
 
Javascript Basics by Bonny
Javascript Basics by BonnyJavascript Basics by Bonny
Javascript Basics by Bonny
Bonny Chacko
 
Slides chapter3part1 ruby-forjavaprogrammers
Slides chapter3part1 ruby-forjavaprogrammersSlides chapter3part1 ruby-forjavaprogrammers
Slides chapter3part1 ruby-forjavaprogrammers
Giovanni924
 

Mais procurados (20)

Java script basics
Java script basicsJava script basics
Java script basics
 
JavaScript Fundamentals & JQuery
JavaScript Fundamentals & JQueryJavaScript Fundamentals & JQuery
JavaScript Fundamentals & JQuery
 
Dollar symbol
Dollar symbolDollar symbol
Dollar symbol
 
Hacking Your Way To Better Security - Dutch PHP Conference 2016
Hacking Your Way To Better Security - Dutch PHP Conference 2016Hacking Your Way To Better Security - Dutch PHP Conference 2016
Hacking Your Way To Better Security - Dutch PHP Conference 2016
 
Design Patterns the Ruby way - ConFoo 2015
Design Patterns the Ruby way - ConFoo 2015Design Patterns the Ruby way - ConFoo 2015
Design Patterns the Ruby way - ConFoo 2015
 
fuser interface-development-using-jquery
fuser interface-development-using-jqueryfuser interface-development-using-jquery
fuser interface-development-using-jquery
 
Jquery introduction
Jquery introductionJquery introduction
Jquery introduction
 
Javascript Basics by Bonny
Javascript Basics by BonnyJavascript Basics by Bonny
Javascript Basics by Bonny
 
Class 2 - Introduction to PHP
Class 2 - Introduction to PHPClass 2 - Introduction to PHP
Class 2 - Introduction to PHP
 
Javascript 101
Javascript 101Javascript 101
Javascript 101
 
Slides chapter3part1 ruby-forjavaprogrammers
Slides chapter3part1 ruby-forjavaprogrammersSlides chapter3part1 ruby-forjavaprogrammers
Slides chapter3part1 ruby-forjavaprogrammers
 
Jquery fundamentals
Jquery fundamentalsJquery fundamentals
Jquery fundamentals
 
Glorp Tutorial Guide
Glorp Tutorial GuideGlorp Tutorial Guide
Glorp Tutorial Guide
 
Cfphp Zce 01 Basics
Cfphp Zce 01 BasicsCfphp Zce 01 Basics
Cfphp Zce 01 Basics
 
Thinking in swift ppt
Thinking in swift pptThinking in swift ppt
Thinking in swift ppt
 
Aniki has come
Aniki has comeAniki has come
Aniki has come
 
PHP variables
PHP  variablesPHP  variables
PHP variables
 
jQuery
jQueryjQuery
jQuery
 
perl_lessons
perl_lessonsperl_lessons
perl_lessons
 
Php Tutorials for Beginners
Php Tutorials for BeginnersPhp Tutorials for Beginners
Php Tutorials for Beginners
 

Semelhante a Data::Verifier and Message::Stack

Building Better Applications with Data::Manager
Building Better Applications with Data::ManagerBuilding Better Applications with Data::Manager
Building Better Applications with Data::Manager
Jay Shirley
 
JSON in Solr: From Top to Bottom - Alexander Rafalovitch, United Nations
JSON in Solr: From Top to Bottom - Alexander Rafalovitch, United NationsJSON in Solr: From Top to Bottom - Alexander Rafalovitch, United Nations
JSON in Solr: From Top to Bottom - Alexander Rafalovitch, United Nations
Lucidworks
 

Semelhante a Data::Verifier and Message::Stack (20)

Building Better Applications with Data::Manager
Building Better Applications with Data::ManagerBuilding Better Applications with Data::Manager
Building Better Applications with Data::Manager
 
Refactoring
RefactoringRefactoring
Refactoring
 
Continuous Integration For Rails Project
Continuous Integration For Rails ProjectContinuous Integration For Rails Project
Continuous Integration For Rails Project
 
Becoming a better WordPress Developer
Becoming a better WordPress DeveloperBecoming a better WordPress Developer
Becoming a better WordPress Developer
 
Micro-service architectures with Gilmour
Micro-service architectures with GilmourMicro-service architectures with Gilmour
Micro-service architectures with Gilmour
 
Workshop quality assurance for php projects - phpdublin
Workshop quality assurance for php projects - phpdublinWorkshop quality assurance for php projects - phpdublin
Workshop quality assurance for php projects - phpdublin
 
Core java complete ppt(note)
Core java  complete  ppt(note)Core java  complete  ppt(note)
Core java complete ppt(note)
 
Jakość dostarczanego oprogramowania oparta o testy
Jakość dostarczanego oprogramowania oparta o testyJakość dostarczanego oprogramowania oparta o testy
Jakość dostarczanego oprogramowania oparta o testy
 
龍華大學前端技術分享 Part1
龍華大學前端技術分享 Part1龍華大學前端技術分享 Part1
龍華大學前端技術分享 Part1
 
Why Your Test Suite Sucks - PHPCon PL 2015
Why Your Test Suite Sucks - PHPCon PL 2015Why Your Test Suite Sucks - PHPCon PL 2015
Why Your Test Suite Sucks - PHPCon PL 2015
 
Where Does the Fat Goes? Utilizando Form Objects Para Simplificar seu Código
Where Does the Fat Goes? Utilizando Form Objects Para Simplificar seu CódigoWhere Does the Fat Goes? Utilizando Form Objects Para Simplificar seu Código
Where Does the Fat Goes? Utilizando Form Objects Para Simplificar seu Código
 
Php Crash Course - Macq Electronique 2010
Php Crash Course - Macq Electronique 2010Php Crash Course - Macq Electronique 2010
Php Crash Course - Macq Electronique 2010
 
JSON in Solr: from top to bottom
JSON in Solr: from top to bottomJSON in Solr: from top to bottom
JSON in Solr: from top to bottom
 
JSON in Solr: From Top to Bottom - Alexander Rafalovitch, United Nations
JSON in Solr: From Top to Bottom - Alexander Rafalovitch, United NationsJSON in Solr: From Top to Bottom - Alexander Rafalovitch, United Nations
JSON in Solr: From Top to Bottom - Alexander Rafalovitch, United Nations
 
Week 7 html css js
Week 7   html css jsWeek 7   html css js
Week 7 html css js
 
IoC with PHP
IoC with PHPIoC with PHP
IoC with PHP
 
Lecture 03 - JQuery.pdf
Lecture 03 - JQuery.pdfLecture 03 - JQuery.pdf
Lecture 03 - JQuery.pdf
 
2015 ZendCon - Do you queue
2015 ZendCon - Do you queue2015 ZendCon - Do you queue
2015 ZendCon - Do you queue
 
C++ basic.ppt
C++ basic.pptC++ basic.ppt
C++ basic.ppt
 
SP24S053 Introduction to PowerShell for SharePoint Developers and Administrators
SP24S053 Introduction to PowerShell for SharePoint Developers and AdministratorsSP24S053 Introduction to PowerShell for SharePoint Developers and Administrators
SP24S053 Introduction to PowerShell for SharePoint Developers and Administrators
 

Último

Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
panagenda
 
Tales from a Passkey Provider Progress from Awareness to Implementation.pptx
Tales from a Passkey Provider  Progress from Awareness to Implementation.pptxTales from a Passkey Provider  Progress from Awareness to Implementation.pptx
Tales from a Passkey Provider Progress from Awareness to Implementation.pptx
FIDO Alliance
 
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptxHarnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
FIDO Alliance
 

Último (20)

Long journey of Ruby Standard library at RubyKaigi 2024
Long journey of Ruby Standard library at RubyKaigi 2024Long journey of Ruby Standard library at RubyKaigi 2024
Long journey of Ruby Standard library at RubyKaigi 2024
 
The Metaverse: Are We There Yet?
The  Metaverse:    Are   We  There  Yet?The  Metaverse:    Are   We  There  Yet?
The Metaverse: Are We There Yet?
 
2024 May Patch Tuesday
2024 May Patch Tuesday2024 May Patch Tuesday
2024 May Patch Tuesday
 
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdfSimplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
 
Using IESVE for Room Loads Analysis - UK & Ireland
Using IESVE for Room Loads Analysis - UK & IrelandUsing IESVE for Room Loads Analysis - UK & Ireland
Using IESVE for Room Loads Analysis - UK & Ireland
 
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
 
Where to Learn More About FDO _ Richard at FIDO Alliance.pdf
Where to Learn More About FDO _ Richard at FIDO Alliance.pdfWhere to Learn More About FDO _ Richard at FIDO Alliance.pdf
Where to Learn More About FDO _ Richard at FIDO Alliance.pdf
 
Event-Driven Architecture Masterclass: Challenges in Stream Processing
Event-Driven Architecture Masterclass: Challenges in Stream ProcessingEvent-Driven Architecture Masterclass: Challenges in Stream Processing
Event-Driven Architecture Masterclass: Challenges in Stream Processing
 
How we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdfHow we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdf
 
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
 
Intro to Passkeys and the State of Passwordless.pptx
Intro to Passkeys and the State of Passwordless.pptxIntro to Passkeys and the State of Passwordless.pptx
Intro to Passkeys and the State of Passwordless.pptx
 
Intro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджераIntro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджера
 
Introduction to FIDO Authentication and Passkeys.pptx
Introduction to FIDO Authentication and Passkeys.pptxIntroduction to FIDO Authentication and Passkeys.pptx
Introduction to FIDO Authentication and Passkeys.pptx
 
Working together SRE & Platform Engineering
Working together SRE & Platform EngineeringWorking together SRE & Platform Engineering
Working together SRE & Platform Engineering
 
The Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and InsightThe Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and Insight
 
Design Guidelines for Passkeys 2024.pptx
Design Guidelines for Passkeys 2024.pptxDesign Guidelines for Passkeys 2024.pptx
Design Guidelines for Passkeys 2024.pptx
 
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdfHow Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
 
Vector Search @ sw2con for slideshare.pptx
Vector Search @ sw2con for slideshare.pptxVector Search @ sw2con for slideshare.pptx
Vector Search @ sw2con for slideshare.pptx
 
Tales from a Passkey Provider Progress from Awareness to Implementation.pptx
Tales from a Passkey Provider  Progress from Awareness to Implementation.pptxTales from a Passkey Provider  Progress from Awareness to Implementation.pptx
Tales from a Passkey Provider Progress from Awareness to Implementation.pptx
 
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptxHarnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
 

Data::Verifier and Message::Stack

  • 1. DATA::VERIFIER & MESSAGE::STACK Invigorating The Forgotten Bits Of Your Web App
  • 2. CORY G WATSON: GPHAT • Magazines.com: Group Director, Development • Cold Hard Code: Creative Director • Contributor and Color Commentator on various projects.
  • 3. BIASES: I HAVE THEM • I’m a closet designer • I hate All-In-One Form handlers • Messaging & Validation are not sexy
  • 4. VALIDATION: PRIMER • Client side is advancing. • It won’t replace server side.* • Duplication of effort.
  • 5. VALIDATION: DATA::FORMVALIDATOR • 8+ years old • Big, Complex
  • 7. D:V – FEATURES • Reusable constraints and coercion • Required, optional & dependents • Length checking • Global and per-field filters
  • 9. WHY MOOSE? • Simplicity • Type Constraints • Coercion • Serialization
  • 10. GETTING STARTED my $dv = Data::Verifier->new(…); my $results = $dv->verify(%params); if($results->success) { # o/ } else { # :( }
  • 11. PROFILE profile => %fields • Simple HashRef • A key for each field • Opposite of D:FV, fields before required/optional
  • 12. FIELD KEYS • coerce • min_length • coercion • post_check • dependent • required • filters • type • max_length
  • 13. EASY ONES • required: Optional? Then it’s not required! • max_length => $x • min_length => $y • type => $moose_type
  • 14. EXAMPLE filters => [ qw(trim) ], profile => { email => { min_length => 5 type => EmailAddress, required => 1 } }
  • 15. COERCE • Same as Moose’s coerce flag • true tells D:V to use Moose coercions • Occludes coercion
  • 16. COERCION • Allows one-off coercions • Does not define a global Moose coercion • Saves cluttering your ::Types with coercions
  • 17. COERCION (CONT) coercion => Data::Verifier::coercion( from => ‘Int’, via => sub { DateTime->from_epoch(epoch => $_) } )
  • 18. DEPENDENT • Field A depends on Field B • More? Field A can depend on an entire profile. • Creates a new D:V, verifies it, merges it with this one.
  • 19. DEPENDENT password => { dependent => { password2 => { required => 1 } } }
  • 20. FILTERS filters => [ qw(trim) ] • Comes with some built-ins. • Also allows CodeRefs • Global and per-field
  • 21. POST_CHECK • Checked at end of verification. • Accepts a CodeRef • Given Results object as argument. • $password1 eq $password2 scenarios
  • 22. POST_CHECK (CONT) post_check => sub { my ($r) = @_; return $r->get_value(‘pass1’) eq $r->get_value(‘pass2’); }
  • 23. RESULT METHODS • get_original_value # unmodified • get_value # filters, coercions • is_missing, is_valid • More!
  • 24. SERIALIZATION • MooseX::Storage • caveat: value isn’t serialized, arbitrary type • use get_original_value • validity and missing is retained
  • 25. MESS-AGING • Error variable • Error ArrayRef • Error plugin?
  • 26. MESSAGING • Context • Level • Localization
  • 27. MESSAGE • id: Localization • level: ‘error’, ‘info’ • params: [ ‘gphat@coldhardcode’ ] • scope: ‘login_form’ • subject: ‘email’ • text: ‘Invalid email address.’
  • 29. MESSAGE::STACK • List of messages • Order is retained • Convenience methods • Many methods return sub-Stacks
  • 30. ADD A MESSAGE $stack->add( id => ‘invalid_email’, scope => ‘login_form’, subject=> ‘email’, level => ‘error’ );
  • 31. BEING INFORMED • count • id, level, scope, subject • has_* (boolean) • for_* (subset Message::Stack)
  • 32. Error Message! Error Message! Line Item 1 Line Item 1 Delivery Options Gift Options Line Item 2 Line Item 2 Delivery Options Gift Options CRAPPY FORM: WHERE ARE
  • 33. Error Message! Line Item 1 Line Item 1 Delivery Options Gift Options Error Message! Line Item 2 Line Item 2 Delivery Options Gift Options GOOD FORM: PRECISE
  • 34. METHODS • Errors: for_level(‘error’); • Sub-Form: for_scope(‘line-item1’); • Specific field: has_subject(‘email’); • Cat: c.loc(message.id, message.params)
  • 35. HINTS • Templates can get messy. • Works well with macros. • Use a lot or a little. • foreach($stack->messages)
  • 36. DATA::VERIFIER + MESSAGE::STACK
  • 38. DATA::MANAGER my $dm = Data::Manager->new; my $v = Data::Verifier->new...; $dm->set_verifier(‘foo’, $v); $dm->verify(‘foo’, { ... }); my $res => $dm->get_results(‘foo’);
  • 39. DATA::MANAGER (CONT) • A single Message::Stack • Multiple Data::Verifier objects (scopes) • success • messages_for_scope
  • 40. SUMMARY • Simplified validation • Reusable types • Serialization for redirects. • Messaging is important. • Context, context, context!
  • 42. COLOPHON • Titling: Tungsten 72pt, Hoefler & Frere-Jones • Body: Hoefler Text 38pt, Hoefler & Frere-Jones • Diagrams: OmniGraffle, The Omni Group • Presentation: Keynote ’09, Apple, Inc • Theme: Modified “Showroom”