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 & 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
 

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::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)
 

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

GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Principled Technologies
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024SynarionITSolutions
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
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
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 

Último (20)

GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
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
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 

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”