• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Perl Moderno
 

Perl Moderno

on

  • 4,719 views

Apresentação sobre Perl Moderno no III FSLDC

Apresentação sobre Perl Moderno no III FSLDC

Statistics

Views

Total Views
4,719
Views on SlideShare
1,797
Embed Views
2,922

Actions

Likes
0
Downloads
17
Comments
1

6 Embeds 2,922

http://pacman.blog.br 2910
http://translate.googleusercontent.com 5
http://optimizelyedit.appspot.com 3
http://web.archive.org 2
http://namao.me 1
http://webcache.googleusercontent.com 1

Accessibility

Categories

Upload Details

Uploaded via as OpenOffice

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel

11 of 1 previous next

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Perl Moderno Perl Moderno Presentation Transcript

    • III FSLDC Modern::Perl Tiago Peczenyj @pac_man http://pacman.blog.br http://rio.pm.org
    • Perl Moderno
    • Modern::Perl
    • Modern Perl?
    • Modern Science?
    • Modern Love?
    • Modern Art?
    • Art of Perl
    • Art of Art
    • Perl of Perl
    • Perl of Perl (...parece uma apresentação do Larry Wall)
    • PERL
    • $==$'; $;||$.| $|;$_ ='*$ ( ^@(%_+&~~;# ~~/.~~ ;_);;.);;#) ;~~~~;_,.~~,.* +,./|~ ~;_);@-, .;.); ~ ~,./@@-__);@-);~~,.*+,. /|);;;~~@-~~~~;;(),. ;.,./@,./@,.;_~~@-););,. ;_);~~,./@,.;;;./@,./ |~~~~;#-(@-__@-__&$#%^';$__ ='`'&'&';$___=&quot;````&quot; |&quot;$[`$[&quot;|'`%&quot;,';$~=(&quot;$___$__-$[``$__&quot;| &quot;$___&quot;| (&quot;$___$__-$[.%&quot;)).(&quot;'`&quot;|&quot;'$[&quot;|&quot;'#&quot;). '/.*?&([^&]*)&.*/$'.++$=.(&quot;/``&quot;|&quot;/$[`&quot;|&quot;/#'&quot;).(&quot;;`/[``$__]//`;&quot; |&quot;;$[/[$[`$__]//`;&quot;|&quot;;#/[$.$__]//'&quot;).'@:=(&quot;@-&quot;,&quot;/.&quot;, &quot;~~&quot;,&quot;;#&quot;,&quot;;;&quot;,&quot;;.&quot;,&quot;,.&quot;,&quot;);&quot;,&quot;()&quot;,&quot;*+&quot;,&quot;__&quot;,&quot;-(&quot;,&quot;/@&quot;,&quot;.%&quot;,&quot;/|&quot;, &quot;;_&quot;);@:{@:}=$%..$#:;'.('`'|&quot;$[&quot;|'#').&quot;/(..)(..)/&quot;.(&quot;```&quot;|&quot;``$[&quot;| '#(&quot;').'(($:{$'.$=.'}<<'.(++$=+$=).')|($:{$'.$=.'}))/'.(&quot;```;&quot;| &quot;``$[;&quot;|&quot;%'#;&quot;).(&quot;````'$__&quot;|&quot;%$[``&quot;|&quot;%&!,&quot;).${$[};`$~$__>&$=`;$_= '*$(^@(%_+&@-__~~;#~~@-;.;;,.(),./.,./|,.-();;#~~@-);;;,.;_~~@-,./., ./@,./@~~@-);;;,.(),.;.~~@-,.,.,.;_,./@,.-();;#~~@-,.;_,./|~~@-,. ,.);););@-@-__~~;#~~@-,.,.,.;_);~~~~@-);;;,.(),.*+);;# ~~@-, ./|,.*+,.,.);;;);*+~~@-,.*+,.;;,.;.,./.~~@-,.,.,.;_) ;~~~ ~@-,.;;,.;.,./@,./.);*+,.;.,.;;@-__~~;#~~@-,.;;,.* +);; #);@-,./@,./.);*+~~@-~~.%~~.%~~@-;;__,. /.);;#@- [email_address] __ ~~;;);/@;#.%;#/.;#-(@-__~~;;;.;_ ;#.%~~~~ ;;() ,.;.,./@,. /@,.;_~~@- ););,.;_ );~~,./ @,. ;;;./@,./| ~~~~;#-(@- __,.,.,. ;_);~~~ ~@ -~~());; #);@-,./@, .*+);;; ~~@-~~ );~~);~~ *+~~@-);-( ~~@-@-_ _~~@- ~~@-);; #,./@,.;., .;.);@ -~~@-; #/.;#-( ~~@-@-__ ~~@-~~ @-);@ -);~~, .*+,./ |);;;~ ~@-~~ ;;;.; _~~@-@ -__);. %;#-( @-__@ -__~~;# ~~@-;; ;#,. ;_,.. %);@-,./@, .*+, ..%, .;.,./|) ;;;) ;;#~ ~@-,.*+,. ,.~~ @-); *+,.;_);;.~ ~);); ~~,.; .~~@-);~~,.;., ./.,.; ;,.*+ ,./|,.); ~~@- );;;,.( ),.*+); ;#~~/|@- __~~;#~~ $';$;;
    • P ratical E xtraction and R eport L anguage
    • Perl foi criado por Larry Wall, inspirado em Shell Script, AWK, SED e C (e uma pitada de linguística)
    • Larry também criou a primeira versão do PATCH e do leitor de news RN
    • Perl 1.0 foi lançado na usenet alt.comp.sources em 18/12/1987
    • Exemplos
    • # fibbonacci - iterativo sub factorial { my $n = shift ; my $result = 1; for my $i (1..$n) { $result *= $i; }; $result; } print “Fatorial de 10 eh ”. factorial (10);
    • # fibbonacci - recursivo sub factorial { my $n = shift ; ($n == 0)? 1 : $n* factorial ($n-1); }
    • # fibbonacci - funcional use List::Util qw(reduce); sub factorial { my $n = shift ; reduce { $a * $b } 1, 1 .. $n }
    • http://rosettacode.org/
    • Linguagem e Cultura estão intimamente ligados
    • Ab Ovo Usque Ad Mala
    • From the Beginning to End
    • Linguagem Depende da Cultura
    • E a Cultura Perl é....
    • COLABORAÇÃO
    • TIMTOWTDI
    • TIMTOWTDI There is More Than One Way To Do It
    • CPAN
    • Comprehensive Perl Archive Network (Perl's Killer Feature)
    • www.cpan.org
    • 95.676 módulos 8.998 autores 259 mirrors
    • “ Nós não nos importamos com a qualidade, Não nos importamos com o propósito, Apenas queremos hospedar os seus módulos&quot;
    • Desafio: como trazer inovação e, ao mesmo tempo, ser estável?
    • Versão Perl Data 1 1987-Dec-18 2 1988-Jun-05 3 1989-Oct-18 4 1991-Mar-21 5 1994-Oct-17
    • Linguagem Criação Versão Atual PHP 1994 5.3.6 Ruby 1995 1.9.2 Python 1991 3.2 Java 1995 1.6.0_25 JavaScript 1995 1.8.5 C# 2001 4.0 C++ 1985 ISO/IEC 14882:2003 / C++0x
    • Algumas linguagens modernas surgiram, evoluiram e se consolidaram durante do período de vida da versão mais recente de Perl
    • Perl 5 é o dialeto atual
    • Perl 6 ainda está em desenvolvimento ( mas é muito, muito legal )
    • Então que Diabos é Perl Moderno?
    • Que versão de Perl vc utiliza?
    • http://perldoc.perl.org/
    • Perl 5.8.9 (que muita gente deve usar ainda...) É de 2008-Dec-14
    • Em 2007-Dec-18 é lançado Perl 5.10.0
    • Big Changes!
      • The feature pragma
      • use feature “:5.10”; use feature qw( … );
    • Antes eu tinha que fazer assim
        #!/usr/bin/perl use strict; use warnings; print “hello worldn”; # argh... não posso esquecer o n no final!
    • Agora podemos escrever
        #!/usr/bin/perl use strict; use warnings; use feature 'say'; say “hello world”;
    • Modern::Perl
      • #!/usr/bin/perl
      • use Modern::Perl;
      • # precisa instalar via CPAN...
      • say “hello world”;
    • Modern::Perl
      • Operador //
      • Given/ When
      • State variables
      • Smart Matching ~~
      • Regular Expression (?<name>...)
      • Pragma mro for Method Resolution Order
        • DFS Depth First Search
        • C3 (like Dylan language)
    • Implicit Strictures in Perl 5.12
        use 5.12.0; significa: use strict; use feature ':5.12';
    • Versão atual: 5.14 ! 5.10 ja está depreciada
    • Suporte a Unicode 6
    • Suporte a IPv6
    • Array and hash container functions accept references!
    • Traditional Syntax Terse Syntax push @$arrayref, @stuff push $arrayref, @stuff pop @$arrayref pop $arrayref shift @$arrayref shift $arrayref values %$hashref values $hashref keys %$hashref keys $hashref
    • Package Block Syntax
        Package Foo::Bar 1.2 { # code }
    • Filehandle method calls load IO::File on demand
        open my $fh, &quot;>&quot;, $file; # loads IO::File and succeeds $fh->autoflush(1); # local $| = 1; $fh->binmode(&quot;:raw&quot;); $fh->close;
    • Modulos Core (alguns...)
      • Carp
      • Data::Dumper
      • Encode
      • English
      • File::Temp
      • Findbin
      • Getopt::Long
      • Scalar::Util
      • List::Util
      • Hash::Util
      • Memoize
      • Module::Pluggable
      • Test::Simple
      • Test::More
      • Tie::File
      • Time::HiRes
    • autodie
        Antes: open(my $fh,&quot;<&quot;,$filename)
          or die &quot;ops...&quot;;
    • autodie
        bIlujDI' yIchegh()Qo'; yIHegh()! It is better to die() than to return() in failure. -- Klingon programming proverb.
    • autodie
        use autodie qw(open close); # open/close succeed or die open(my $fh, &quot;<&quot;, $filename); # No need to check!
    • CPAN!
    • Antes o tratamento de erros era assim
        eval {
          ...algum codigo que pode lançar um erro...
        }; if($@){ # cuidado! $@ é global! :/
          print &quot;opa...&quot;;
        }
    • Try::Tiny
        use Try::Tiny; try {
          algum codigo que pode lançar um erro
        } catch {
          warn &quot;opa... ocorreu um erro $_&quot;;
        } finally {
          ...
        };
    • Moose
    • Perl 5 é Orientado a Objetos!
    • package Point; sub new { # construtor! my $klass = shift ; my $self = { x => 0, y => 0}; bless $self, $klass; } # criando um acessor para a prop. x sub x { my $self = shift ; my $x = shift ; $self->{x} = $x // $self->{x}; }
    • Moose is a postmodern object system for Perl 5
    • package Point; use Moose; has 'x' => (is => 'rw', isa => 'Int'); has 'y' => (is => 'rw', isa => 'Int'); sub clear { my $self = shift; $self->x(0); $self->y(0); }
    • package Point3D; use Moose; extends 'Point'; has 'z' => (is => 'rw', isa => 'Int'); after 'clear' => sub { my $self = shift; $self->z(0); } __PACKAGE__->meta->make_immutable;
    • Roles
    • package Breakable; use Moose::Role; has 'is_broken' => ( is => 'rw', isa => 'Bool' ); sub break { shift->is_broken(1); }
    • package Car; use Moose; with 'Breakable'; ...
    • Outros Modulos
      • DateTime
      • Smart::Comments
      • IO::All
      • Perl::Tidy
      • Perl::Critic
      • Email::Simple
      • Text::CSV_XS
      • Config::Any
      • DBI
      • Dist::Zilla
      • Devel::NYTProf
      • Devel::Cover
      • Log::Log4Perl
      • POE
      • WWW::Mechanize
      • Task::Kensho
    • Shell
        use Shell qw(cat ps cp); $passwd = cat('</etc/passwd'); @pslines = ps('-ww'); cp(&quot;/etc/passwd&quot;, &quot;/tmp/passwd&quot;); # Forma OO, utilizando “method missing” my $sh = Shell->new; print $sh->ls('-l');
    • Inline::C
        use Inline C => <<'END_C'; void greet() { printf(&quot;Hello, worldn&quot;); } END_C greet; # imprime hello world from C
    • Attribute::Util
        use Attribute::Memoize; sub fib :Memoize { my $n = shift; return $n if $n < 2; fib($n-1) + fib($n-2); } say fib($_) for 1..50;
      • Attribute::Overload
        use Attribute::Overload; sub add : Overload(+) { # ... }
    • Template Toolkit
    • DBIx::Class
    • Catalyst
    • Dancer
    • Mojolicious
    • ojo
        perl -Mojo -e '
          a(&quot;/&quot; => {text => &quot;Hello Mojo!&quot;})->start
        ' daemon a : any g : get p : post u : put d : delete
    • Mojolicious::Lite
        use Mojolicious::Lite; # Route with placeholder get '/:foo' => sub { my $self = shift; my $foo = $self->param('foo'); $self->render(text => &quot;Hello from $foo!&quot;); }; # Start the Mojolicious command system app->start;
    • Mojolicious::Lite
        # /foo?user=bar get '/foo' => sub { my $self = shift; my $user = $self->param('user'); $self->stash(one => 23); $self->render('baz', two => 24, u => $user); }; __DATA__ @@ baz.html.ep Hello <%=$u%> with <%=$one%> and <%=$two%>.
    • Mojolicious::Lite
        websocket '/echo' => sub { my $self = shift; $self->on_message(sub { my ($self, $message) = @_; $self->send_message(&quot;echo: $message&quot;); }); };
    • http://mojolicio.us/perldoc
    • Mojolicious
    • mojo generate app MyApp
    • MAC179013:palestra peczenyj$ mojo generate app MyApp [mkdir] /Users/peczenyj/palestra/my_app/script [write] /Users/peczenyj/palestra/my_app/script/my_app [chmod] my_app/script/my_app 744 [mkdir] /Users/peczenyj/palestra/my_app/lib [write] /Users/peczenyj/palestra/my_app/lib/MyApp.pm [mkdir] /Users/peczenyj/palestra/my_app/lib/MyApp [write] /Users/peczenyj/palestra/my_app/lib/MyApp/Example.pm [mkdir] /Users/peczenyj/palestra/my_app/t [write] /Users/peczenyj/palestra/my_app/t/basic.t [mkdir] /Users/peczenyj/palestra/my_app/log [mkdir] /Users/peczenyj/palestra/my_app/public [write] /Users/peczenyj/palestra/my_app/public/index.html [mkdir] /Users/peczenyj/palestra/my_app/templates/layouts [write] /Users/peczenyj/palestra/my_app/templates/layouts/default.html.ep [mkdir] /Users/peczenyj/palestra/my_app/templates/example [write] /Users/peczenyj/palestra/my_app/templates/example/welcome.html.ep
    • package MyApp; # in my_app/lib use Mojo::Base 'Mojolicious'; # This method will run once at server start sub startup { my $self = shift; # Documentation browser under &quot;/perldoc&quot; $self->plugin('pod_renderer'); # Routes my $r = $self->routes; # Normal route to controller $r->route('/welcome')->to('example#welcome'); } 1;
    • package MyApp::Example; use Mojo::Base 'Mojolicious::Controller'; # This action will render a template sub welcome { my $self = shift; # Render template &quot;example/welcome.html.ep&quot; # with message $self->render(message => 'Welcome to the Mojolicious Web Framework!'); } 1;
    • templates/layouts/default.htmp.ep <!doctype html><html> <head><title><%= title %></title></head> <body><%= content %></body> </html> templates/example/welcome.html.ep % layout 'default'; % title 'Welcome'; <h2><%= $message %></h2> This page was generated from the template
    • #!/usr/bin/env perl use strict; use warnings; use Test::More tests => 5; use Test::Mojo; use_ok 'MyApp'; # Test my $t = Test::Mojo->new(app => 'MyApp'); $t->get_ok('/welcome')->status_is(200) ->content_type_is('text/html;charset=UTF-8') ->content_like(qr/Mojolicious Web Framework/i);
    • Perl5i
    • Perl 6
    • Livros Modern Perl – Chromatic (free) Learning Perl – Randal Schwartz Programming Perl – Larry Wall Intermediate Perl Randal Schwartz Mastering Perl – Brian d foy Perl Best Practices – Damian Conway High Order Perl – Mark Jason Dominus
    • E utilizando o perldoc $ perldoc -f builtinFunction $ perldoc -q FAQ $ perldoc Some::Module $ perldoc perlhist Disponivel em html ou pdf no site perldoc.perl.org
    • Language Reference
      • perlsyn – sintaxe
      • perldata – data types
      • perlsub – subrotinas
      • perlvar – variaveis predefinidas
      • perltie – variaveis “tie”
      • perlport – escrever codigo portavel !
      • perlperf – tecnicas de performance
      • perlmod – modulos e tabela de simbolos
    • Tutoriais
      • perlstyle – style guide
      • perlreftut – references
      • perlretut – regular expressions
      • perlunitut – unicode
      • perllol – arrays of arrays
      • perlopentut – open things
      • perlboot – Beginner's OO
      • perlxstut – sobre XS
    • Obrigado