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

Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 

Dernier (20)

Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 

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”