SlideShare uma empresa Scribd logo
1 de 40
Perl
Perl
Hate it for the right reasons
“Perl is an abomination.”
“Perl is an abomination.”
               Matt Follett, circa 2006
“Perl is an abomination.”
                               Matt Follett, circa 2006
     while talking to president of the Perl Foundation
Old Views of Perl
$;=$/;seek+DATA,!++$/,!$s;$_=<DATA>;$s&&print||$g&&do{$y=($x||=20)*($y||8);sub
i{sleep&f}sub'p{print$;x$=,join$;,$b=~/.{$x}/g}$j=$j;sub'f{pop}sub
n{substr($b,&f%$y,3)=~tr,O,O,}sub'g{$f=&f-1;($w,$w,substr($b,&f,1),O)[n($f-$x)+
n($x+$f)-(substr($b,&f,1)eq+O)+n$f]||$w}$w="40";$b=join'',@ARGV?<>:$_,$w
x$y;$b=~s).)$&=~/w/?O:$w)ge;substr($b,$y)=q++;$g='$i=0;$i?$b:$c=$b;
substr+$c,$i,1,g$i;$g=~s?d+?($&+1)%$y?e;$i-$y+1?eval$g:do{$i=-1;$b=$c;p;i
1}';sub'e{eval$g;&e}e}||eval||die+No.$;
__DATA__
if($j){{$^W=$|;*_=sub{$=+s=#([A-z])(.*)#=#$+$1#=g}}
@s=(q[$_=sprintf+pop@s,@s],q[
if($j){{$^W=$|;*_=sub{$=+s=#([A-z])(.*)#=#$+$1#=g}} #_The_Perl_Journal_#
@s=(q[%s],q[%s])x2;%s;print"n"x&_,$_;i$j;eval}
])x2;$_=sprintf+pop@s,@s;print"n"x&_,$_;i$j;eval}$/=$y;$"=",";print
q<#!/usr/local/bin/perl -sw
if(!$s){>.($_=<>).q<}else{@s=(q[printf+pop@s,@s],q[#!/usr/local/bin/perl -sw
if(!$s){>.(s$%$%%$g,tr=[=[===tr=]=]=||&d,$_).q<}else{@s=(q[%s],q[%s])x2;%s}
])x2;printf+pop@s,@s}
>
                                            SelfGOL - obfuscated Perl contest entry by Damien Conway
Slightly More Modern Perl
package PerkyProfiler::Service::Role::OwnsUri;
use Moose::Role;
requires 'source';
use URI;

sub owns_uri {
  my ($self, $uri) = @_;

     $uri = URI->new($uri) if not UNIVERSAL::isa( $uri, 'URI' );
     my $source = $self->source;
     return ( $uri->host() =~ /.$source./i )
}
1;
Modern Perl
use MooseX::Declare; use MooseX::MultiMethod;
use Moose::Role;
use URI;

role PerkyProfiler::Service::Role::OwnsUri requires 'source'
{
  multi method owns_uri( URI $uri) {

      my $source = $self->source;

      return ( $uri->host() =~ /.$source./i )
  }
}
1;
Hate it because it does a lot
Meta Object Protocol
new object system on top of MOP
Several nice web frameworks
functional programming
Hate it because it’s
hard to give a talk on
Project
Vending machine
Project
Vending machine
   except, instead of vending items it vends ‘identities’
Project
Vending machine
   except, instead of vending items it vends ‘identities’
   and instead of taking ‘coins’ it takes ‘URL’s
Project
Vending machine
   except, instead of vending items it vends ‘identities’
   and instead of taking ‘coins’ it takes ‘URL’s
   and instead of being a ‘machine’ it is a ‘website’
Project
Vending machine
   except, instead of vending items it vends ‘identities’
   and instead of taking ‘coins’ it takes ‘URL’s
   and instead of being a ‘machine’ it is a ‘website’
   and instead of having states it is ‘stateless’
Project
Vending machine
   except, instead of vending items it vends ‘identities’
   and instead of taking ‘coins’ it takes ‘URL’s
   and instead of being a ‘machine’ it is a ‘website’
   and instead of having states it is ‘stateless’
   ...
PerkyProfiler
The post modern multi service
profiling application all the kids
 are talking about these days.
Goals of project
Given a URL
    get info about the contributor on that service
    comb other services for information on that user
Services chosen
    GitHub
    Flickr
    Twitter
Use CPAN when possible
Web Frameworks

Catalyst
Gantry
Jifty
CGI::App
Catalyst
Simple
MVC Framework
Has many Models and Views to choose from
Easy to write new ones
Easy to plug other things in
Lots of helper scripts
Helpers
Start an app:
   catalyst.pl PerkyProfiler
Add a model:
   ./script/perkyprofiler_create.pl model Profiler
Add a view:
   ./script/perkyprofiler_create.pl view Main TTSite
Incorporating a new Model
package PerkyProfiler::Model::Profiler;

use strict;
use warnings;
use parent 'Catalyst::Model::Adaptor';

__PACKAGE__->config( class => 'PerkyProfiler::Profiler');
Use new model
sub index :Path :Args(0) {
    my ( $self, $c ) = @_;
...
    my $profiler = $c->model('Profiler');

  my $entity;
  eval {
     $entity = $profiler->generate_entity_from_uri($c->req->param('url'));
     $profiler->loop_update_entity($entity);
     $c->stash->{'entity'} = $entity;
  };
  if( my $err = $@) {
     $c->stash->{'message'} = "Sorry, but an error occured:" . $err->message(); }}
Profiler

loop_update_entity
   given an entity loops through and updates it
generate_entity_from_uri
   Generates a new entity object from a given URI
Example Service: Flickr
package PerkyProfiler::Service::Flickr;

use Flickr::Simple2;
use PerkyProfiler::Entity;
use PerkyProfiler::Entity::Attribute;

use Moose;
with 'PerkyProfiler::Service::Role';

has _core => ( isa => 'Flickr::Simple2', is => 'rw');
has key => ( isa => 'Str', is => 'ro' );
has secret => ( isa => 'Str', is => 'ro' );
has _contributed => ( isa => 'Bool', is => 'rw', default => 0 );
Moose
“Post Modern” Object System that provides:
   roles
   declarative definitions
   delegation
   typing
   method modifiers
   …and more!
Declarative Style Classes Ex
has _core => (
   isa => ‘Flickr::Simple2’,
   is => ‘rw’,
   handles =>
     { entity_from_username => 'get_user_byUsername'
       entity_from_url       => 'get_user_byUrl ' }
);
Declarative Style Class Defs
Simply say what it has, eg, “has key => ( isa => 'Str',   is => 'ro' )”
Declare different things:
    is - read/write permissions
    default - default value, or sub that generates the value
    lazy - lazy generation
    required
    delegated tasks
    isa - type
Types?
Yes, perl is loosely typed, but Moose checks for you.
It can do:
   predefined types like strings, integers, numbers
   ref too, eg, ArrayRef[CodeRef] is an array of subs
   classes
   custom types
Custom Types
New types
   type ‘two_chars’ => where { defined $_ && length
   $_ == 2};
Subtypes
   subtype ‘EvenInt’ => as ‘Int’ => where { $_ % 2 + 1}
   => message {“Please provide an even number”}
Back to the example
package PerkyProfiler::Service::Flickr;

use Flickr::Simple2;
use PerkyProfiler::Entity;
use PerkyProfiler::Entity::Attribute;

use Moose;
with 'PerkyProfiler::Service::Role';

has _core => ( isa => 'Flickr::Simple2', is => 'rw');
has key => ( isa => 'Str', is => 'ro' );
has secret => ( isa => 'Str', is => 'ro' );
has _contributed => ( isa => 'Bool', is => 'rw', default => 0 );
Moose Roles
 Roles can be used simply by saying: “with
 'PerkyProfiler::Service::Role';”

 Roles allow you to define a list of methods that must exist
 (an interface)
 Roles also allow you to define a list of methods that
 cannot exist
 Finally roles can provide you with additional functionality
 (mixin)
New Example: Service::Role
package PerkyProfiler::Service::Role;

use Moose::Role;
with 'PerkyProfiler::Service::Role::UsernameGenerator';
with 'PerkyProfiler::Service::Role::OwnsUri';

requires '_get_user_from_uri';
requires '_get_user_info';
requires 'map_to_entity';
requires 'contributor';
Providing a Role
Just `use Moose::Role;`
Roles can consume other Roles
Roles can require subs via requires, eg, requires
‘map_to_entity’
Roles can exclude other roles via excludes, eg, exclude
‘ConflictingRole’
Example: Working with Roles
        Objects can be introspected for roles

foreach my $service ( $self->_services->gen_iterator->() )
{
   if($service->meta->does_role($owns_uri_role))
{
      if($service->owns_uri($uri))
{
            return $service->entity_from_uri($uri);
}}}
What else can Moose do?

Meta everything (Meta attributes, classes, roles)
Anonymous classes
autoboxing with MooseX::Autobox
multimethod dispatching with MooseX::MultiMethod
What else does Perl have?

DBIx::Class
   Object Relational Mapper
   classes are based off tables, but can be reassigned
   columns can be custom inflated
What we missed
Perl’s Functional
Programming Techniques
St. Louis Perl Monger’s proudly present:

 August 17th, 6:30 PM
4444 Forest Park Pkwy
  Intro to Functional
 Programming in Perl
                                           with Bill Odom

Mais conteúdo relacionado

Mais procurados

Inside Bokete: Web Application with Mojolicious and others
Inside Bokete:  Web Application with Mojolicious and othersInside Bokete:  Web Application with Mojolicious and others
Inside Bokete: Web Application with Mojolicious and othersYusuke Wada
 
Perl web frameworks
Perl web frameworksPerl web frameworks
Perl web frameworksdiego_k
 
A reviravolta do desenvolvimento web
A reviravolta do desenvolvimento webA reviravolta do desenvolvimento web
A reviravolta do desenvolvimento webWallace Reis
 
Keeping it small: Getting to know the Slim micro framework
Keeping it small: Getting to know the Slim micro frameworkKeeping it small: Getting to know the Slim micro framework
Keeping it small: Getting to know the Slim micro frameworkJeremy Kendall
 
PSGI and Plack from first principles
PSGI and Plack from first principlesPSGI and Plack from first principles
PSGI and Plack from first principlesPerl Careers
 
Web Apps in Perl - HTTP 101
Web Apps in Perl - HTTP 101Web Apps in Perl - HTTP 101
Web Apps in Perl - HTTP 101hendrikvb
 
Mojolicious. Веб в коробке!
Mojolicious. Веб в коробке!Mojolicious. Веб в коробке!
Mojolicious. Веб в коробке!Anatoly Sharifulin
 
Mojolicious - A new hope
Mojolicious - A new hopeMojolicious - A new hope
Mojolicious - A new hopeMarcus Ramberg
 
Introduction To Moco
Introduction To MocoIntroduction To Moco
Introduction To MocoNaoya Ito
 
Keeping it small - Getting to know the Slim PHP micro framework
Keeping it small - Getting to know the Slim PHP micro frameworkKeeping it small - Getting to know the Slim PHP micro framework
Keeping it small - Getting to know the Slim PHP micro frameworkJeremy Kendall
 
Lightweight Webservices with Sinatra and RestClient
Lightweight Webservices with Sinatra and RestClientLightweight Webservices with Sinatra and RestClient
Lightweight Webservices with Sinatra and RestClientAdam Wiggins
 
Slim RedBeanPHP and Knockout
Slim RedBeanPHP and KnockoutSlim RedBeanPHP and Knockout
Slim RedBeanPHP and KnockoutVic Metcalfe
 
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
 
Building Modern and Secure PHP Applications – Codementor Office Hours with Be...
Building Modern and Secure PHP Applications – Codementor Office Hours with Be...Building Modern and Secure PHP Applications – Codementor Office Hours with Be...
Building Modern and Secure PHP Applications – Codementor Office Hours with Be...Arc & Codementor
 

Mais procurados (20)

Inside Bokete: Web Application with Mojolicious and others
Inside Bokete:  Web Application with Mojolicious and othersInside Bokete:  Web Application with Mojolicious and others
Inside Bokete: Web Application with Mojolicious and others
 
Mojo as a_client
Mojo as a_clientMojo as a_client
Mojo as a_client
 
Perl web frameworks
Perl web frameworksPerl web frameworks
Perl web frameworks
 
A reviravolta do desenvolvimento web
A reviravolta do desenvolvimento webA reviravolta do desenvolvimento web
A reviravolta do desenvolvimento web
 
Keeping it small: Getting to know the Slim micro framework
Keeping it small: Getting to know the Slim micro frameworkKeeping it small: Getting to know the Slim micro framework
Keeping it small: Getting to know the Slim micro framework
 
Developing apps using Perl
Developing apps using PerlDeveloping apps using Perl
Developing apps using Perl
 
PSGI and Plack from first principles
PSGI and Plack from first principlesPSGI and Plack from first principles
PSGI and Plack from first principles
 
Web Apps in Perl - HTTP 101
Web Apps in Perl - HTTP 101Web Apps in Perl - HTTP 101
Web Apps in Perl - HTTP 101
 
Mojolicious. Веб в коробке!
Mojolicious. Веб в коробке!Mojolicious. Веб в коробке!
Mojolicious. Веб в коробке!
 
Mojolicious - A new hope
Mojolicious - A new hopeMojolicious - A new hope
Mojolicious - A new hope
 
Introduction To Moco
Introduction To MocoIntroduction To Moco
Introduction To Moco
 
Follow the White Rabbit - Message Queues with PHP
Follow the White Rabbit - Message Queues with PHPFollow the White Rabbit - Message Queues with PHP
Follow the White Rabbit - Message Queues with PHP
 
About Data::ObjectDriver
About Data::ObjectDriverAbout Data::ObjectDriver
About Data::ObjectDriver
 
Keeping it small - Getting to know the Slim PHP micro framework
Keeping it small - Getting to know the Slim PHP micro frameworkKeeping it small - Getting to know the Slim PHP micro framework
Keeping it small - Getting to know the Slim PHP micro framework
 
Lies, Damn Lies, and Benchmarks
Lies, Damn Lies, and BenchmarksLies, Damn Lies, and Benchmarks
Lies, Damn Lies, and Benchmarks
 
Lightweight Webservices with Sinatra and RestClient
Lightweight Webservices with Sinatra and RestClientLightweight Webservices with Sinatra and RestClient
Lightweight Webservices with Sinatra and RestClient
 
Slim RedBeanPHP and Knockout
Slim RedBeanPHP and KnockoutSlim RedBeanPHP and Knockout
Slim RedBeanPHP and Knockout
 
Mojolicious on Steroids
Mojolicious on SteroidsMojolicious on Steroids
Mojolicious on Steroids
 
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 ...
 
Building Modern and Secure PHP Applications – Codementor Office Hours with Be...
Building Modern and Secure PHP Applications – Codementor Office Hours with Be...Building Modern and Secure PHP Applications – Codementor Office Hours with Be...
Building Modern and Secure PHP Applications – Codementor Office Hours with Be...
 

Semelhante a Perl: Hate it for the Right Reasons

Best Practices in Plugin Development (WordCamp Seattle)
Best Practices in Plugin Development (WordCamp Seattle)Best Practices in Plugin Development (WordCamp Seattle)
Best Practices in Plugin Development (WordCamp Seattle)andrewnacin
 
Doctrine For Beginners
Doctrine For BeginnersDoctrine For Beginners
Doctrine For BeginnersJonathan Wage
 
Think Generic - Add API's To Your Custom Modules
Think Generic - Add API's To Your Custom ModulesThink Generic - Add API's To Your Custom Modules
Think Generic - Add API's To Your Custom ModulesJens Sørensen
 
Modern Web Development with Perl
Modern Web Development with PerlModern Web Development with Perl
Modern Web Development with PerlDave Cross
 
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
 
Replacing "exec" with a type and provider
Replacing "exec" with a type and providerReplacing "exec" with a type and provider
Replacing "exec" with a type and providerDominic Cleal
 
SADI in Perl - Protege Plugin Tutorial (fixed Aug 24, 2011)
SADI in Perl - Protege Plugin Tutorial (fixed Aug 24, 2011)SADI in Perl - Protege Plugin Tutorial (fixed Aug 24, 2011)
SADI in Perl - Protege Plugin Tutorial (fixed Aug 24, 2011)Mark Wilkinson
 
REST with Eve and Python
REST with Eve and PythonREST with Eve and Python
REST with Eve and PythonPiXeL16
 
Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)
Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)
Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)James Titcumb
 
Lithium: The Framework for People Who Hate Frameworks
Lithium: The Framework for People Who Hate FrameworksLithium: The Framework for People Who Hate Frameworks
Lithium: The Framework for People Who Hate FrameworksNate Abele
 
Entities in drupal 7
Entities in drupal 7Entities in drupal 7
Entities in drupal 7Zsolt Tasnadi
 
Go OO! - Real-life Design Patterns in PHP 5
Go OO! - Real-life Design Patterns in PHP 5Go OO! - Real-life Design Patterns in PHP 5
Go OO! - Real-life Design Patterns in PHP 5Stephan Schmidt
 
I, For One, Welcome Our New Perl6 Overlords
I, For One, Welcome Our New Perl6 OverlordsI, For One, Welcome Our New Perl6 Overlords
I, For One, Welcome Our New Perl6 Overlordsheumann
 
Drupal 7 Entity & Entity API
Drupal 7 Entity & Entity APIDrupal 7 Entity & Entity API
Drupal 7 Entity & Entity API均民 戴
 
Building and Distributing PostgreSQL Extensions Without Learning C
Building and Distributing PostgreSQL Extensions Without Learning CBuilding and Distributing PostgreSQL Extensions Without Learning C
Building and Distributing PostgreSQL Extensions Without Learning CDavid Wheeler
 
laravel tricks in 50minutes
laravel tricks in 50minuteslaravel tricks in 50minutes
laravel tricks in 50minutesBarang CK
 
50 Laravel Tricks in 50 Minutes
50 Laravel Tricks in 50 Minutes50 Laravel Tricks in 50 Minutes
50 Laravel Tricks in 50 MinutesAzim Kurt
 

Semelhante a Perl: Hate it for the Right Reasons (20)

Best Practices in Plugin Development (WordCamp Seattle)
Best Practices in Plugin Development (WordCamp Seattle)Best Practices in Plugin Development (WordCamp Seattle)
Best Practices in Plugin Development (WordCamp Seattle)
 
Mojolicious
MojoliciousMojolicious
Mojolicious
 
Doctrine For Beginners
Doctrine For BeginnersDoctrine For Beginners
Doctrine For Beginners
 
Think Generic - Add API's To Your Custom Modules
Think Generic - Add API's To Your Custom ModulesThink Generic - Add API's To Your Custom Modules
Think Generic - Add API's To Your Custom Modules
 
Modern Web Development with Perl
Modern Web Development with PerlModern Web Development with Perl
Modern Web Development with Perl
 
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 ...
 
Replacing "exec" with a type and provider
Replacing "exec" with a type and providerReplacing "exec" with a type and provider
Replacing "exec" with a type and provider
 
SADI in Perl - Protege Plugin Tutorial (fixed Aug 24, 2011)
SADI in Perl - Protege Plugin Tutorial (fixed Aug 24, 2011)SADI in Perl - Protege Plugin Tutorial (fixed Aug 24, 2011)
SADI in Perl - Protege Plugin Tutorial (fixed Aug 24, 2011)
 
Bioinformatica 10-11-2011-p6-bioperl
Bioinformatica 10-11-2011-p6-bioperlBioinformatica 10-11-2011-p6-bioperl
Bioinformatica 10-11-2011-p6-bioperl
 
Mojolicious
MojoliciousMojolicious
Mojolicious
 
REST with Eve and Python
REST with Eve and PythonREST with Eve and Python
REST with Eve and Python
 
Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)
Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)
Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)
 
Lithium: The Framework for People Who Hate Frameworks
Lithium: The Framework for People Who Hate FrameworksLithium: The Framework for People Who Hate Frameworks
Lithium: The Framework for People Who Hate Frameworks
 
Entities in drupal 7
Entities in drupal 7Entities in drupal 7
Entities in drupal 7
 
Go OO! - Real-life Design Patterns in PHP 5
Go OO! - Real-life Design Patterns in PHP 5Go OO! - Real-life Design Patterns in PHP 5
Go OO! - Real-life Design Patterns in PHP 5
 
I, For One, Welcome Our New Perl6 Overlords
I, For One, Welcome Our New Perl6 OverlordsI, For One, Welcome Our New Perl6 Overlords
I, For One, Welcome Our New Perl6 Overlords
 
Drupal 7 Entity & Entity API
Drupal 7 Entity & Entity APIDrupal 7 Entity & Entity API
Drupal 7 Entity & Entity API
 
Building and Distributing PostgreSQL Extensions Without Learning C
Building and Distributing PostgreSQL Extensions Without Learning CBuilding and Distributing PostgreSQL Extensions Without Learning C
Building and Distributing PostgreSQL Extensions Without Learning C
 
laravel tricks in 50minutes
laravel tricks in 50minuteslaravel tricks in 50minutes
laravel tricks in 50minutes
 
50 Laravel Tricks in 50 Minutes
50 Laravel Tricks in 50 Minutes50 Laravel Tricks in 50 Minutes
50 Laravel Tricks in 50 Minutes
 

Último

Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Kaya Weers
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkPixlogix Infotech
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observabilityitnewsafrica
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfNeo4j
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfpanagenda
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxfnnc6jmgwh
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesBernd Ruecker
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Nikki Chapple
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 

Último (20)

Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App Framework
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdf
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architectures
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 

Perl: Hate it for the Right Reasons

  • 2. Perl Hate it for the right reasons
  • 3. “Perl is an abomination.”
  • 4. “Perl is an abomination.” Matt Follett, circa 2006
  • 5. “Perl is an abomination.” Matt Follett, circa 2006 while talking to president of the Perl Foundation
  • 6. Old Views of Perl $;=$/;seek+DATA,!++$/,!$s;$_=<DATA>;$s&&print||$g&&do{$y=($x||=20)*($y||8);sub i{sleep&f}sub'p{print$;x$=,join$;,$b=~/.{$x}/g}$j=$j;sub'f{pop}sub n{substr($b,&f%$y,3)=~tr,O,O,}sub'g{$f=&f-1;($w,$w,substr($b,&f,1),O)[n($f-$x)+ n($x+$f)-(substr($b,&f,1)eq+O)+n$f]||$w}$w="40";$b=join'',@ARGV?<>:$_,$w x$y;$b=~s).)$&=~/w/?O:$w)ge;substr($b,$y)=q++;$g='$i=0;$i?$b:$c=$b; substr+$c,$i,1,g$i;$g=~s?d+?($&+1)%$y?e;$i-$y+1?eval$g:do{$i=-1;$b=$c;p;i 1}';sub'e{eval$g;&e}e}||eval||die+No.$; __DATA__ if($j){{$^W=$|;*_=sub{$=+s=#([A-z])(.*)#=#$+$1#=g}} @s=(q[$_=sprintf+pop@s,@s],q[ if($j){{$^W=$|;*_=sub{$=+s=#([A-z])(.*)#=#$+$1#=g}} #_The_Perl_Journal_# @s=(q[%s],q[%s])x2;%s;print"n"x&_,$_;i$j;eval} ])x2;$_=sprintf+pop@s,@s;print"n"x&_,$_;i$j;eval}$/=$y;$"=",";print q<#!/usr/local/bin/perl -sw if(!$s){>.($_=<>).q<}else{@s=(q[printf+pop@s,@s],q[#!/usr/local/bin/perl -sw if(!$s){>.(s$%$%%$g,tr=[=[===tr=]=]=||&d,$_).q<}else{@s=(q[%s],q[%s])x2;%s} ])x2;printf+pop@s,@s} > SelfGOL - obfuscated Perl contest entry by Damien Conway
  • 7. Slightly More Modern Perl package PerkyProfiler::Service::Role::OwnsUri; use Moose::Role; requires 'source'; use URI; sub owns_uri { my ($self, $uri) = @_; $uri = URI->new($uri) if not UNIVERSAL::isa( $uri, 'URI' ); my $source = $self->source; return ( $uri->host() =~ /.$source./i ) } 1;
  • 8. Modern Perl use MooseX::Declare; use MooseX::MultiMethod; use Moose::Role; use URI; role PerkyProfiler::Service::Role::OwnsUri requires 'source' { multi method owns_uri( URI $uri) { my $source = $self->source; return ( $uri->host() =~ /.$source./i ) } } 1;
  • 9. Hate it because it does a lot Meta Object Protocol new object system on top of MOP Several nice web frameworks functional programming
  • 10. Hate it because it’s hard to give a talk on
  • 12. Project Vending machine except, instead of vending items it vends ‘identities’
  • 13. Project Vending machine except, instead of vending items it vends ‘identities’ and instead of taking ‘coins’ it takes ‘URL’s
  • 14. Project Vending machine except, instead of vending items it vends ‘identities’ and instead of taking ‘coins’ it takes ‘URL’s and instead of being a ‘machine’ it is a ‘website’
  • 15. Project Vending machine except, instead of vending items it vends ‘identities’ and instead of taking ‘coins’ it takes ‘URL’s and instead of being a ‘machine’ it is a ‘website’ and instead of having states it is ‘stateless’
  • 16. Project Vending machine except, instead of vending items it vends ‘identities’ and instead of taking ‘coins’ it takes ‘URL’s and instead of being a ‘machine’ it is a ‘website’ and instead of having states it is ‘stateless’ ...
  • 17. PerkyProfiler The post modern multi service profiling application all the kids are talking about these days.
  • 18. Goals of project Given a URL get info about the contributor on that service comb other services for information on that user Services chosen GitHub Flickr Twitter Use CPAN when possible
  • 20. Catalyst Simple MVC Framework Has many Models and Views to choose from Easy to write new ones Easy to plug other things in Lots of helper scripts
  • 21. Helpers Start an app: catalyst.pl PerkyProfiler Add a model: ./script/perkyprofiler_create.pl model Profiler Add a view: ./script/perkyprofiler_create.pl view Main TTSite
  • 22. Incorporating a new Model package PerkyProfiler::Model::Profiler; use strict; use warnings; use parent 'Catalyst::Model::Adaptor'; __PACKAGE__->config( class => 'PerkyProfiler::Profiler');
  • 23. Use new model sub index :Path :Args(0) { my ( $self, $c ) = @_; ... my $profiler = $c->model('Profiler'); my $entity; eval { $entity = $profiler->generate_entity_from_uri($c->req->param('url')); $profiler->loop_update_entity($entity); $c->stash->{'entity'} = $entity; }; if( my $err = $@) { $c->stash->{'message'} = "Sorry, but an error occured:" . $err->message(); }}
  • 24. Profiler loop_update_entity given an entity loops through and updates it generate_entity_from_uri Generates a new entity object from a given URI
  • 25. Example Service: Flickr package PerkyProfiler::Service::Flickr; use Flickr::Simple2; use PerkyProfiler::Entity; use PerkyProfiler::Entity::Attribute; use Moose; with 'PerkyProfiler::Service::Role'; has _core => ( isa => 'Flickr::Simple2', is => 'rw'); has key => ( isa => 'Str', is => 'ro' ); has secret => ( isa => 'Str', is => 'ro' ); has _contributed => ( isa => 'Bool', is => 'rw', default => 0 );
  • 26. Moose “Post Modern” Object System that provides: roles declarative definitions delegation typing method modifiers …and more!
  • 27. Declarative Style Classes Ex has _core => ( isa => ‘Flickr::Simple2’, is => ‘rw’, handles => { entity_from_username => 'get_user_byUsername' entity_from_url => 'get_user_byUrl ' } );
  • 28. Declarative Style Class Defs Simply say what it has, eg, “has key => ( isa => 'Str', is => 'ro' )” Declare different things: is - read/write permissions default - default value, or sub that generates the value lazy - lazy generation required delegated tasks isa - type
  • 29. Types? Yes, perl is loosely typed, but Moose checks for you. It can do: predefined types like strings, integers, numbers ref too, eg, ArrayRef[CodeRef] is an array of subs classes custom types
  • 30. Custom Types New types type ‘two_chars’ => where { defined $_ && length $_ == 2}; Subtypes subtype ‘EvenInt’ => as ‘Int’ => where { $_ % 2 + 1} => message {“Please provide an even number”}
  • 31. Back to the example package PerkyProfiler::Service::Flickr; use Flickr::Simple2; use PerkyProfiler::Entity; use PerkyProfiler::Entity::Attribute; use Moose; with 'PerkyProfiler::Service::Role'; has _core => ( isa => 'Flickr::Simple2', is => 'rw'); has key => ( isa => 'Str', is => 'ro' ); has secret => ( isa => 'Str', is => 'ro' ); has _contributed => ( isa => 'Bool', is => 'rw', default => 0 );
  • 32. Moose Roles Roles can be used simply by saying: “with 'PerkyProfiler::Service::Role';” Roles allow you to define a list of methods that must exist (an interface) Roles also allow you to define a list of methods that cannot exist Finally roles can provide you with additional functionality (mixin)
  • 33. New Example: Service::Role package PerkyProfiler::Service::Role; use Moose::Role; with 'PerkyProfiler::Service::Role::UsernameGenerator'; with 'PerkyProfiler::Service::Role::OwnsUri'; requires '_get_user_from_uri'; requires '_get_user_info'; requires 'map_to_entity'; requires 'contributor';
  • 34. Providing a Role Just `use Moose::Role;` Roles can consume other Roles Roles can require subs via requires, eg, requires ‘map_to_entity’ Roles can exclude other roles via excludes, eg, exclude ‘ConflictingRole’
  • 35. Example: Working with Roles Objects can be introspected for roles foreach my $service ( $self->_services->gen_iterator->() ) { if($service->meta->does_role($owns_uri_role)) { if($service->owns_uri($uri)) { return $service->entity_from_uri($uri); }}}
  • 36. What else can Moose do? Meta everything (Meta attributes, classes, roles) Anonymous classes autoboxing with MooseX::Autobox multimethod dispatching with MooseX::MultiMethod
  • 37. What else does Perl have? DBIx::Class Object Relational Mapper classes are based off tables, but can be reassigned columns can be custom inflated
  • 40. St. Louis Perl Monger’s proudly present: August 17th, 6:30 PM 4444 Forest Park Pkwy Intro to Functional Programming in Perl with Bill Odom