SlideShare une entreprise Scribd logo
1  sur  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”

Contenu connexe

Tendances

JavaScript Fundamentals & JQuery
JavaScript Fundamentals & JQueryJavaScript Fundamentals & JQuery
JavaScript Fundamentals & JQueryJamshid Hashimi
 
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 2016Colin O'Dell
 
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 2015Fred Heath
 
fuser interface-development-using-jquery
fuser interface-development-using-jqueryfuser interface-development-using-jquery
fuser interface-development-using-jqueryKostas Mavridis
 
Javascript Basics by Bonny
Javascript Basics by BonnyJavascript Basics by Bonny
Javascript Basics by BonnyBonny Chacko
 
Class 2 - Introduction to PHP
Class 2 - Introduction to PHPClass 2 - Introduction to PHP
Class 2 - Introduction to PHPAhmed Swilam
 
Slides chapter3part1 ruby-forjavaprogrammers
Slides chapter3part1 ruby-forjavaprogrammersSlides chapter3part1 ruby-forjavaprogrammers
Slides chapter3part1 ruby-forjavaprogrammersGiovanni924
 
Glorp Tutorial Guide
Glorp Tutorial GuideGlorp Tutorial Guide
Glorp Tutorial GuideESUG
 
Thinking in swift ppt
Thinking in swift pptThinking in swift ppt
Thinking in swift pptKeith Moon
 

Tendances (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
 

Similaire à 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::ManagerJay Shirley
 
Continuous Integration For Rails Project
Continuous Integration For Rails ProjectContinuous Integration For Rails Project
Continuous Integration For Rails ProjectLouie Zhao
 
Becoming a better WordPress Developer
Becoming a better WordPress DeveloperBecoming a better WordPress Developer
Becoming a better WordPress DeveloperJoey Kudish
 
Micro-service architectures with Gilmour
Micro-service architectures with GilmourMicro-service architectures with Gilmour
Micro-service architectures with GilmourAditya Godbole
 
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 - phpdublinMichelangelo van Dam
 
Core java complete ppt(note)
Core java  complete  ppt(note)Core java  complete  ppt(note)
Core java complete ppt(note)arvind pandey
 
Jakość dostarczanego oprogramowania oparta o testy
Jakość dostarczanego oprogramowania oparta o testyJakość dostarczanego oprogramowania oparta o testy
Jakość dostarczanego oprogramowania oparta o testyPaweł Tekliński
 
龍華大學前端技術分享 Part1
龍華大學前端技術分享 Part1龍華大學前端技術分享 Part1
龍華大學前端技術分享 Part1Jia-Long Yeh
 
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 2015CiaranMcNulty
 
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ódigoGuilherme
 
Php Crash Course - Macq Electronique 2010
Php Crash Course - Macq Electronique 2010Php Crash Course - Macq Electronique 2010
Php Crash Course - Macq Electronique 2010Michelangelo van Dam
 
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 NationsLucidworks
 
Lecture 03 - JQuery.pdf
Lecture 03 - JQuery.pdfLecture 03 - JQuery.pdf
Lecture 03 - JQuery.pdfLê Thưởng
 
2015 ZendCon - Do you queue
2015 ZendCon - Do you queue2015 ZendCon - Do you queue
2015 ZendCon - Do you queueMike Willbanks
 
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 AdministratorsMichael Blumenthal (Microsoft MVP)
 

Similaire à 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
 

Dernier

Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesZilliz
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 

Dernier (20)

Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector Databases
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 

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”