SlideShare una empresa de Scribd logo
1 de 44
Modern Perl
use v5.10;
say ,[object Object]
print my_sub_call(...), "
"; ,[object Object],[object Object]
say  my_sub_call(...);
Defined or ,[object Object]
or $name  // = 'oleber';
switch ,[object Object]
switch ,[object Object]
Smart matching ,[object Object]
or if ( @array  ~~  /pippo/ ) {   … }
state ,[object Object]
or  sub xpto {   state  $static_var = 0;   ... }
New RegExp ,[object Object]
"K" escape, floating length positive lookbehind: s/(foo)bar/$1/g becomes s/fooKbar//g
Backtracking control verbs
...
Object Oriented
use Moose; package Person; use Moose; # now it's a Moose class! # imports  strict  and  warnings ... no Moose ; __PACKAGE__->meta->make_immutable ;
Moose  attributes has  id => ( is   =>  'ro' , isa  =>  'Int' , ); has  name => ( is   =>  'rw' , isa  =>  'Str' , ); my $person =  new Person(id => 123, name => ' John '); $person->name('peter'); # OK $person->id(12);  # NOK
Moose Types ,[object Object]
HashRef[CodeRef] # a hash of str to Code ref
...
Define your types use Moose::Util::TypeConstraints; subtype  'Telephone' =>  as   'Str' =>  where  { $_ =~ /^d+$/}; no Moose::Util::TypeConstraints; has telephone => ( is  => 'rw', isa =>  'Telephone' , ); $person->telephone('35196219374'); # OK $person->telephone('XPTO');  # NOK
Moose class Inheritance package User; use Moose; extends  'Person'; has login => ( is  => 'rw', isa => 'Str', ); ... my $user = new User(id => 52, login => 'oleber')
Moose Method sub do_login { my ($self, $password) = @_; ... }
Moose method modifiers before  do_login => sub { my ( $self, $pass ) = @_; warn "Called login() with $pass
"; }; around  name => sub { my ($orig, $self, @args) = @_; return ucfirst lc  $self->$orig( @args ) ; }; ...
Moose Constructor ,[object Object]
Moose Destructor  ,[object Object]
The old DESTROY is used  internally  by Moose
You shall use the  DEMOLISH()  method
Call methods on native types
autobox use JSON; say to_json [ map { $_ ** 2 } @array ]; use autobox; local *ARRAY::map = sub { my ( $self, $block ) = @_; return [map {&$block($_)} @$self ]; }; local *ARRAY::to_json = sub { return to_json(shift); }; say @array->map( sub { $_ ** 2 } )->to_json;
autobox ,[object Object]
[1..10]->foreach(sub { ... }) resolves to: ARRAY::foreach([1..10], sub { ... })
autobox ,[object Object]
Cpan has already some Packages with the most logical functions implementation. See: ,[object Object]
Moose::Autobox
Exception handling
Error use Error qw(:try); try  { throw ...; }  catch  Error::IO with { my $E = shift; warn "File $E->{'-file'} had a problem
"; }  except  { my $E = shift; warn "ERROR: " . Dumper $E; }  otherwise  { say "ALL OK
"; }  finally  { say "Finished" } ;  # Don't forget the trailing ;
TryCatch use TryCatch; try  { die ... }  catch  ( PKG_1 $e  where  { $_->code > 100 } ) { ... }  catch  ( PKG_2 $e ) { ... }  catch  ( $e ) { ... }  catch  { ... }
It is better to die() than to return() in failure. (Paul Fenwick) The Box Jellyfish Saltwater Crocodile Blue Ring Octopus Stone fish Red Back Spider Funnel Web Spider
autodie open(my $FH, ">>", $path) or die "Can't open $!"; system($cmd) == 0 or die "system failed: $?"; if ( defined ( my $pid = fork() ) ) { if ( $pid != 0 ) { # parent } else { # child } } else { die "Can't fork"; }
autodie use autodie qw(:all); open(my $FH, ">>", $path) or die "Can't open $!"; system($cmd) == 0 or die "system failed: $?"; if ( defined ( my $pid = fork() ) ) { if ( $pid != 0 ) { # parent } else { # child } } else { die "Can't fork"; }

Más contenido relacionado

La actualidad más candente

DBIx::Class introduction - 2010
DBIx::Class introduction - 2010DBIx::Class introduction - 2010
DBIx::Class introduction - 2010leo lapworth
 
Puppet Camp Chicago 2014: Smoothing Troubles With Custom Types and Providers ...
Puppet Camp Chicago 2014: Smoothing Troubles With Custom Types and Providers ...Puppet Camp Chicago 2014: Smoothing Troubles With Custom Types and Providers ...
Puppet Camp Chicago 2014: Smoothing Troubles With Custom Types and Providers ...Puppet
 
Advanced Perl Techniques
Advanced Perl TechniquesAdvanced Perl Techniques
Advanced Perl TechniquesDave Cross
 
LPW: Beginners Perl
LPW: Beginners PerlLPW: Beginners Perl
LPW: Beginners PerlDave Cross
 
Migrating to Puppet 4.0
Migrating to Puppet 4.0Migrating to Puppet 4.0
Migrating to Puppet 4.0Puppet
 
Puppet Camp Paris 2015: Power of Puppet 4 (Beginner)
Puppet Camp Paris 2015: Power of Puppet 4 (Beginner) Puppet Camp Paris 2015: Power of Puppet 4 (Beginner)
Puppet Camp Paris 2015: Power of Puppet 4 (Beginner) Puppet
 
Introduction to Perl Best Practices
Introduction to Perl Best PracticesIntroduction to Perl Best Practices
Introduction to Perl Best PracticesJosé Castro
 
Doctrine MongoDB ODM (PDXPHP)
Doctrine MongoDB ODM (PDXPHP)Doctrine MongoDB ODM (PDXPHP)
Doctrine MongoDB ODM (PDXPHP)Kris Wallsmith
 
Constructive Destructor Use
Constructive Destructor UseConstructive Destructor Use
Constructive Destructor Usemetaperl
 
WordPress Cuztom Helper
WordPress Cuztom HelperWordPress Cuztom Helper
WordPress Cuztom Helperslicejack
 
Advanced symfony Techniques
Advanced symfony TechniquesAdvanced symfony Techniques
Advanced symfony TechniquesKris Wallsmith
 
Moose: Perl Objects
Moose: Perl ObjectsMoose: Perl Objects
Moose: Perl ObjectsLambert Lum
 
Non-Relational Databases
Non-Relational DatabasesNon-Relational Databases
Non-Relational Databaseskchodorow
 
Replacing "exec" with a type and provider: Return manifests to a declarative ...
Replacing "exec" with a type and provider: Return manifests to a declarative ...Replacing "exec" with a type and provider: Return manifests to a declarative ...
Replacing "exec" with a type and provider: Return manifests to a declarative ...Puppet
 
"The worst code I ever wrote"
"The worst code I ever wrote""The worst code I ever wrote"
"The worst code I ever wrote"Tomas Doran
 

La actualidad más candente (19)

DBIx::Class introduction - 2010
DBIx::Class introduction - 2010DBIx::Class introduction - 2010
DBIx::Class introduction - 2010
 
Puppet Camp Chicago 2014: Smoothing Troubles With Custom Types and Providers ...
Puppet Camp Chicago 2014: Smoothing Troubles With Custom Types and Providers ...Puppet Camp Chicago 2014: Smoothing Troubles With Custom Types and Providers ...
Puppet Camp Chicago 2014: Smoothing Troubles With Custom Types and Providers ...
 
Advanced Perl Techniques
Advanced Perl TechniquesAdvanced Perl Techniques
Advanced Perl Techniques
 
LPW: Beginners Perl
LPW: Beginners PerlLPW: Beginners Perl
LPW: Beginners Perl
 
Migrating to Puppet 4.0
Migrating to Puppet 4.0Migrating to Puppet 4.0
Migrating to Puppet 4.0
 
Puppet Camp Paris 2015: Power of Puppet 4 (Beginner)
Puppet Camp Paris 2015: Power of Puppet 4 (Beginner) Puppet Camp Paris 2015: Power of Puppet 4 (Beginner)
Puppet Camp Paris 2015: Power of Puppet 4 (Beginner)
 
Introduction to Perl Best Practices
Introduction to Perl Best PracticesIntroduction to Perl Best Practices
Introduction to Perl Best Practices
 
Doctrine MongoDB ODM (PDXPHP)
Doctrine MongoDB ODM (PDXPHP)Doctrine MongoDB ODM (PDXPHP)
Doctrine MongoDB ODM (PDXPHP)
 
Constructive Destructor Use
Constructive Destructor UseConstructive Destructor Use
Constructive Destructor Use
 
WordPress Cuztom Helper
WordPress Cuztom HelperWordPress Cuztom Helper
WordPress Cuztom Helper
 
Perl
PerlPerl
Perl
 
Advanced symfony Techniques
Advanced symfony TechniquesAdvanced symfony Techniques
Advanced symfony Techniques
 
Fantom and Tales
Fantom and TalesFantom and Tales
Fantom and Tales
 
Moose: Perl Objects
Moose: Perl ObjectsMoose: Perl Objects
Moose: Perl Objects
 
Perl Basics for Pentesters Part 1
Perl Basics for Pentesters Part 1Perl Basics for Pentesters Part 1
Perl Basics for Pentesters Part 1
 
Non-Relational Databases
Non-Relational DatabasesNon-Relational Databases
Non-Relational Databases
 
Replacing "exec" with a type and provider: Return manifests to a declarative ...
Replacing "exec" with a type and provider: Return manifests to a declarative ...Replacing "exec" with a type and provider: Return manifests to a declarative ...
Replacing "exec" with a type and provider: Return manifests to a declarative ...
 
ReUse Your (Puppet) Modules!
ReUse Your (Puppet) Modules!ReUse Your (Puppet) Modules!
ReUse Your (Puppet) Modules!
 
"The worst code I ever wrote"
"The worst code I ever wrote""The worst code I ever wrote"
"The worst code I ever wrote"
 

Destacado

Java. Lecture 03. OOP and UML
Java. Lecture 03. OOP and UMLJava. Lecture 03. OOP and UML
Java. Lecture 03. OOP and UMLcolriot
 
Mojolicious - Perl Framework for the Real-Time Web (Lightning Talk)
Mojolicious - Perl Framework for the Real-Time Web (Lightning Talk)Mojolicious - Perl Framework for the Real-Time Web (Lightning Talk)
Mojolicious - Perl Framework for the Real-Time Web (Lightning Talk)Dotan Dimet
 
A very nice presentation on Moose.
A very nice presentation on Moose.A very nice presentation on Moose.
A very nice presentation on Moose.Chankey Pathak
 
Mojolicious, real-time web framework
Mojolicious, real-time web frameworkMojolicious, real-time web framework
Mojolicious, real-time web frameworktaggg
 
Mojolicious: what works and what doesn't
Mojolicious: what works and what doesn'tMojolicious: what works and what doesn't
Mojolicious: what works and what doesn'tCosimo Streppone
 

Destacado (10)

Perl5i
Perl5iPerl5i
Perl5i
 
Java. Lecture 03. OOP and UML
Java. Lecture 03. OOP and UMLJava. Lecture 03. OOP and UML
Java. Lecture 03. OOP and UML
 
Mojolicious - Perl Framework for the Real-Time Web (Lightning Talk)
Mojolicious - Perl Framework for the Real-Time Web (Lightning Talk)Mojolicious - Perl Framework for the Real-Time Web (Lightning Talk)
Mojolicious - Perl Framework for the Real-Time Web (Lightning Talk)
 
RESTful web services
RESTful web servicesRESTful web services
RESTful web services
 
A very nice presentation on Moose.
A very nice presentation on Moose.A very nice presentation on Moose.
A very nice presentation on Moose.
 
Mojolicious, real-time web framework
Mojolicious, real-time web frameworkMojolicious, real-time web framework
Mojolicious, real-time web framework
 
Modern Perl
Modern  PerlModern  Perl
Modern Perl
 
Mojolicious
MojoliciousMojolicious
Mojolicious
 
Mojolicious: what works and what doesn't
Mojolicious: what works and what doesn'tMojolicious: what works and what doesn't
Mojolicious: what works and what doesn't
 
Mojolicious and REST
Mojolicious and RESTMojolicious and REST
Mojolicious and REST
 

Similar a Modern Perl

Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)Kang-min Liu
 
Barely Legal Xxx Perl Presentation
Barely Legal Xxx Perl PresentationBarely Legal Xxx Perl Presentation
Barely Legal Xxx Perl PresentationAttila Balazs
 
Perl Bag of Tricks - Baltimore Perl mongers
Perl Bag of Tricks  -  Baltimore Perl mongersPerl Bag of Tricks  -  Baltimore Perl mongers
Perl Bag of Tricks - Baltimore Perl mongersbrian d foy
 
Zendcon 2007 Features
Zendcon 2007 FeaturesZendcon 2007 Features
Zendcon 2007 Featuresfivespeed5
 
Maybe you do not know that ...
Maybe you do not know that ...Maybe you do not know that ...
Maybe you do not know that ...Viktor Turskyi
 
Exploiting Php With Php
Exploiting Php With PhpExploiting Php With Php
Exploiting Php With PhpJeremy Coates
 
What's new in Perl 5.10?
What's new in Perl 5.10?What's new in Perl 5.10?
What's new in Perl 5.10?acme
 
Introduction to Perl
Introduction to PerlIntroduction to Perl
Introduction to PerlDave Cross
 
Dealing with Legacy Perl Code - Peter Scott
Dealing with Legacy Perl Code - Peter ScottDealing with Legacy Perl Code - Peter Scott
Dealing with Legacy Perl Code - Peter ScottO'Reilly Media
 
Introduction to Perl - Day 1
Introduction to Perl - Day 1Introduction to Perl - Day 1
Introduction to Perl - Day 1Dave Cross
 
Descobrindo a linguagem Perl
Descobrindo a linguagem PerlDescobrindo a linguagem Perl
Descobrindo a linguagem Perlgarux
 
Ods Markup And Tagsets: A Tutorial
Ods Markup And Tagsets: A TutorialOds Markup And Tagsets: A Tutorial
Ods Markup And Tagsets: A Tutorialsimienc
 
Moose (Perl 5)
Moose (Perl 5)Moose (Perl 5)
Moose (Perl 5)xSawyer
 
Top 10 php classic traps confoo
Top 10 php classic traps confooTop 10 php classic traps confoo
Top 10 php classic traps confooDamien Seguy
 
Top 10 php classic traps php serbia
Top 10 php classic traps php serbiaTop 10 php classic traps php serbia
Top 10 php classic traps php serbiaDamien Seguy
 

Similar a Modern Perl (20)

Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)
 
Barely Legal Xxx Perl Presentation
Barely Legal Xxx Perl PresentationBarely Legal Xxx Perl Presentation
Barely Legal Xxx Perl Presentation
 
Perl Moderno
Perl ModernoPerl Moderno
Perl Moderno
 
Perl Bag of Tricks - Baltimore Perl mongers
Perl Bag of Tricks  -  Baltimore Perl mongersPerl Bag of Tricks  -  Baltimore Perl mongers
Perl Bag of Tricks - Baltimore Perl mongers
 
Zendcon 2007 Features
Zendcon 2007 FeaturesZendcon 2007 Features
Zendcon 2007 Features
 
Cleancode
CleancodeCleancode
Cleancode
 
Maybe you do not know that ...
Maybe you do not know that ...Maybe you do not know that ...
Maybe you do not know that ...
 
Perl Presentation
Perl PresentationPerl Presentation
Perl Presentation
 
Exploiting Php With Php
Exploiting Php With PhpExploiting Php With Php
Exploiting Php With Php
 
What's new in Perl 5.10?
What's new in Perl 5.10?What's new in Perl 5.10?
What's new in Perl 5.10?
 
Introduction to Perl
Introduction to PerlIntroduction to Perl
Introduction to Perl
 
Dealing with Legacy Perl Code - Peter Scott
Dealing with Legacy Perl Code - Peter ScottDealing with Legacy Perl Code - Peter Scott
Dealing with Legacy Perl Code - Peter Scott
 
Introduction to Perl - Day 1
Introduction to Perl - Day 1Introduction to Perl - Day 1
Introduction to Perl - Day 1
 
Bag of tricks
Bag of tricksBag of tricks
Bag of tricks
 
Descobrindo a linguagem Perl
Descobrindo a linguagem PerlDescobrindo a linguagem Perl
Descobrindo a linguagem Perl
 
Ods Markup And Tagsets: A Tutorial
Ods Markup And Tagsets: A TutorialOds Markup And Tagsets: A Tutorial
Ods Markup And Tagsets: A Tutorial
 
Moose (Perl 5)
Moose (Perl 5)Moose (Perl 5)
Moose (Perl 5)
 
Top 10 php classic traps confoo
Top 10 php classic traps confooTop 10 php classic traps confoo
Top 10 php classic traps confoo
 
C to perl binding
C to perl bindingC to perl binding
C to perl binding
 
Top 10 php classic traps php serbia
Top 10 php classic traps php serbiaTop 10 php classic traps php serbia
Top 10 php classic traps php serbia
 

Último

Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbuapidays
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
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
 
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
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
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
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusZilliz
 
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
 
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
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
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
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
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
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 

Último (20)

Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
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
 
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
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
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
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
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
 
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...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
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
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
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
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 

Modern Perl

  • 3.
  • 4.
  • 6.
  • 7. or $name // = 'oleber';
  • 8.
  • 9.
  • 10.
  • 11. or if ( @array ~~ /pippo/ ) { … }
  • 12.
  • 13. or sub xpto { state $static_var = 0; ... }
  • 14.
  • 15. "K" escape, floating length positive lookbehind: s/(foo)bar/$1/g becomes s/fooKbar//g
  • 17. ...
  • 19. use Moose; package Person; use Moose; # now it's a Moose class! # imports strict and warnings ... no Moose ; __PACKAGE__->meta->make_immutable ;
  • 20. Moose attributes has id => ( is => 'ro' , isa => 'Int' , ); has name => ( is => 'rw' , isa => 'Str' , ); my $person = new Person(id => 123, name => ' John '); $person->name('peter'); # OK $person->id(12); # NOK
  • 21.
  • 22. HashRef[CodeRef] # a hash of str to Code ref
  • 23. ...
  • 24. Define your types use Moose::Util::TypeConstraints; subtype 'Telephone' => as 'Str' => where { $_ =~ /^d+$/}; no Moose::Util::TypeConstraints; has telephone => ( is => 'rw', isa => 'Telephone' , ); $person->telephone('35196219374'); # OK $person->telephone('XPTO'); # NOK
  • 25. Moose class Inheritance package User; use Moose; extends 'Person'; has login => ( is => 'rw', isa => 'Str', ); ... my $user = new User(id => 52, login => 'oleber')
  • 26. Moose Method sub do_login { my ($self, $password) = @_; ... }
  • 27. Moose method modifiers before do_login => sub { my ( $self, $pass ) = @_; warn "Called login() with $pass "; }; around name => sub { my ($orig, $self, @args) = @_; return ucfirst lc $self->$orig( @args ) ; }; ...
  • 28.
  • 29.
  • 30. The old DESTROY is used internally by Moose
  • 31. You shall use the DEMOLISH() method
  • 32. Call methods on native types
  • 33. autobox use JSON; say to_json [ map { $_ ** 2 } @array ]; use autobox; local *ARRAY::map = sub { my ( $self, $block ) = @_; return [map {&$block($_)} @$self ]; }; local *ARRAY::to_json = sub { return to_json(shift); }; say @array->map( sub { $_ ** 2 } )->to_json;
  • 34.
  • 35. [1..10]->foreach(sub { ... }) resolves to: ARRAY::foreach([1..10], sub { ... })
  • 36.
  • 37.
  • 40. Error use Error qw(:try); try { throw ...; } catch Error::IO with { my $E = shift; warn "File $E->{'-file'} had a problem "; } except { my $E = shift; warn "ERROR: " . Dumper $E; } otherwise { say "ALL OK "; } finally { say "Finished" } ; # Don't forget the trailing ;
  • 41. TryCatch use TryCatch; try { die ... } catch ( PKG_1 $e where { $_->code > 100 } ) { ... } catch ( PKG_2 $e ) { ... } catch ( $e ) { ... } catch { ... }
  • 42. It is better to die() than to return() in failure. (Paul Fenwick) The Box Jellyfish Saltwater Crocodile Blue Ring Octopus Stone fish Red Back Spider Funnel Web Spider
  • 43. autodie open(my $FH, ">>", $path) or die "Can't open $!"; system($cmd) == 0 or die "system failed: $?"; if ( defined ( my $pid = fork() ) ) { if ( $pid != 0 ) { # parent } else { # child } } else { die "Can't fork"; }
  • 44. autodie use autodie qw(:all); open(my $FH, ">>", $path) or die "Can't open $!"; system($cmd) == 0 or die "system failed: $?"; if ( defined ( my $pid = fork() ) ) { if ( $pid != 0 ) { # parent } else { # child } } else { die "Can't fork"; }
  • 45. autodie use autodie qw(:all); open(my $FH, ">>", $path); system($cmd) == 0 or die "system failed: $?"; if ( defined ( my $pid = fork() ) ) { if ( $pid != 0 ) { # parent } else { # child } } else { die "Can't fork"; }
  • 46. autodie use autodie qw(:all); open(my $FH, ">>", $path); system($cmd); if ( defined ( my $pid = fork() ) ) { if ( $pid != 0 ) { # parent } else { # child } } else { die "Can't fork"; }
  • 47. autodie use autodie qw(:all); open(my $FH, ">>", $path); system($cmd); if ( ( my $pid = fork() ) != 0 ) { # parent } else { # child }
  • 48. autodie error analyse eval { use autodie; open(my $FH, '<', $some_file); while ( my $line = readline $FH ) { ... } close($fh); }; given ($@) { when (undef) { say &quot;No error&quot;; } when ('open') { say &quot;Error from open&quot;; } when (':io') { say &quot;Non-open, IO error.&quot;; } when (':all') { say &quot;autodie error.&quot; } default { say &quot;Not an autodie error.&quot; } }
  • 49.
  • 50.
  • 54.
  • 56.
  • 58.
  • 59.
  • 60.
  • 61. hard to read code
  • 63.
  • 65. Test::Simple use Test::Simple tests => 2; ok ( 1 + 1 == 2, &quot;sum&quot; ); ok ( 2 * 3 == 5, &quot;multiplication&quot;); prints: 1..2 ok 1 - sum not ok 2 - multiplication # Failed test 'multiplication' # at script.t line 6. # Looks like you failed 1 test of 2.
  • 66. Test::More Complex stuff use Test::More 'no_plan'; ok ( 1 + 1 == 2, &quot;sum&quot; ); is ( 1 + 1, 2, 'add'); isnt ( 2 * 3, 5, 'multiplication'); is_deeply ({1..4}, {1=>2, 3=>4}, &quot;similar hash&quot;); my $str = 'Hello, World!'; like ($str, qr/Hello/, 'match'); unlike ($str, qr/Dude/, 'No way Dude'); use_ok ('Person'); can_ok ('Person', 'name'); ...
  • 67.
  • 68. Test::Output - Test STDOUT and STDERR messages.
  • 69. Test::DatabaseRow - Simple database tests
  • 70. Test::WWW::Mechanize - Test web application
  • 71. Apache::Test - Test Apache
  • 72. ...
  • 73. ? Question & Answers