Perl Moderno
Upcoming SlideShare
Loading in...5
×
 

Like this? Share it with your network

Share

Perl Moderno

on

  • 4,806 views

Apresentação sobre Perl Moderno no III FSLDC

Apresentação sobre Perl Moderno no III FSLDC

Statistics

Views

Total Views
4,806
Views on SlideShare
1,884
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
  • 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 Presentation Transcript

  • 1. III FSLDC Modern::Perl Tiago Peczenyj @pac_man http://pacman.blog.br http://rio.pm.org
  • 2. Perl Moderno
  • 3. Modern::Perl
  • 4. Modern Perl?
  • 5. Modern Science?
  • 6. Modern Love?
  • 7. Modern Art?
  • 8. Art of Perl
  • 9. Art of Art
  • 10. Perl of Perl
  • 11. Perl of Perl (...parece uma apresentação do Larry Wall)
  • 12. PERL
  • 13. $==$'; $;||$.| $|;$_ ='*$ ( ^@(%_+&~~;# ~~/.~~ ;_);;.);;#) ;~~~~;_,.~~,.* +,./|~ ~;_);@-, .;.); ~ ~,./@@-__);@-);~~,.*+,. /|);;;~~@-~~~~;;(),. ;.,./@,./@,.;_~~@-););,. ;_);~~,./@,.;;;./@,./ |~~~~;#-(@-__@-__&$#%^';$__ ='`'&'&';$___=&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] __ ~~;;);/@;#.%;#/.;#-(@-__~~;;;.;_ ;#.%~~~~ ;;() ,.;.,./@,. /@,.;_~~@- ););,.;_ );~~,./ @,. ;;;./@,./| ~~~~;#-(@- __,.,.,. ;_);~~~ ~@ -~~());; #);@-,./@, .*+);;; ~~@-~~ );~~);~~ *+~~@-);-( ~~@-@-_ _~~@- ~~@-);; #,./@,.;., .;.);@ -~~@-; #/.;#-( ~~@-@-__ ~~@-~~ @-);@ -);~~, .*+,./ |);;;~ ~@-~~ ;;;.; _~~@-@ -__);. %;#-( @-__@ -__~~;# ~~@-;; ;#,. ;_,.. %);@-,./@, .*+, ..%, .;.,./|) ;;;) ;;#~ ~@-,.*+,. ,.~~ @-); *+,.;_);;.~ ~);); ~~,.; .~~@-);~~,.;., ./.,.; ;,.*+ ,./|,.); ~~@- );;;,.( ),.*+); ;#~~/|@- __~~;#~~ $';$;;
  • 14. P ratical E xtraction and R eport L anguage
  • 15. Perl foi criado por Larry Wall, inspirado em Shell Script, AWK, SED e C (e uma pitada de linguística)
  • 16. Larry também criou a primeira versão do PATCH e do leitor de news RN
  • 17. Perl 1.0 foi lançado na usenet alt.comp.sources em 18/12/1987
  • 18. Exemplos
  • 19. # 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);
  • 20. # fibbonacci - recursivo sub factorial { my $n = shift ; ($n == 0)? 1 : $n* factorial ($n-1); }
  • 21. # fibbonacci - funcional use List::Util qw(reduce); sub factorial { my $n = shift ; reduce { $a * $b } 1, 1 .. $n }
  • 22. http://rosettacode.org/
  • 23. Linguagem e Cultura estão intimamente ligados
  • 24. Ab Ovo Usque Ad Mala
  • 25. From the Beginning to End
  • 26. Linguagem Depende da Cultura
  • 27. E a Cultura Perl é....
  • 28. COLABORAÇÃO
  • 29. TIMTOWTDI
  • 30. TIMTOWTDI There is More Than One Way To Do It
  • 31. CPAN
  • 32. Comprehensive Perl Archive Network (Perl's Killer Feature)
  • 33. www.cpan.org
  • 34. 95.676 módulos 8.998 autores 259 mirrors
  • 35. “ 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;
  • 36. Desafio: como trazer inovação e, ao mesmo tempo, ser estável?
  • 37. Versão Perl Data 1 1987-Dec-18 2 1988-Jun-05 3 1989-Oct-18 4 1991-Mar-21 5 1994-Oct-17
  • 38. 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
  • 39. Algumas linguagens modernas surgiram, evoluiram e se consolidaram durante do período de vida da versão mais recente de Perl
  • 40. Perl 5 é o dialeto atual
  • 41. Perl 6 ainda está em desenvolvimento ( mas é muito, muito legal )
  • 42. Então que Diabos é Perl Moderno?
  • 43. Que versão de Perl vc utiliza?
  • 44. http://perldoc.perl.org/
  • 45. Perl 5.8.9 (que muita gente deve usar ainda...) É de 2008-Dec-14
  • 46. Em 2007-Dec-18 é lançado Perl 5.10.0
  • 47. Big Changes!
  • 48.
      The feature pragma
  • 49.
      use feature “:5.10”; use feature qw( … );
  • 50. 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!
  • 51. Agora podemos escrever
      #!/usr/bin/perl use strict; use warnings; use feature 'say'; say “hello world”;
  • 52. Modern::Perl
    • #!/usr/bin/perl
    • 53. use Modern::Perl;
    • 54. # precisa instalar via CPAN...
    • 55. say “hello world”;
  • 56. Modern::Perl
    • Operador //
    • 57. Given/ When
    • 58. State variables
    • 59. Smart Matching ~~
    • 60. Regular Expression (?<name>...)
    • 61. Pragma mro for Method Resolution Order
      • DFS Depth First Search
      • 62. C3 (like Dylan language)
  • 63. Implicit Strictures in Perl 5.12
      use 5.12.0; significa: use strict; use feature ':5.12';
  • 64. Versão atual: 5.14 ! 5.10 ja está depreciada
  • 65. Suporte a Unicode 6
  • 66. Suporte a IPv6
  • 67. Array and hash container functions accept references!
  • 68. 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
  • 69. Package Block Syntax
      Package Foo::Bar 1.2 { # code }
  • 70. 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;
  • 71. Modulos Core (alguns...)
    • Carp
    • 72. Data::Dumper
    • 73. Encode
    • 74. English
    • 75. File::Temp
    • 76. Findbin
    • 77. Getopt::Long
    • 78. Scalar::Util
    • List::Util
    • 79. Hash::Util
    • 80. Memoize
    • 81. Module::Pluggable
    • 82. Test::Simple
    • 83. Test::More
    • 84. Tie::File
    • 85. Time::HiRes
  • 86. autodie
      Antes: open(my $fh,&quot;<&quot;,$filename)
        or die &quot;ops...&quot;;
  • 87. autodie
      bIlujDI' yIchegh()Qo'; yIHegh()! It is better to die() than to return() in failure. -- Klingon programming proverb.
  • 88. autodie
      use autodie qw(open close); # open/close succeed or die open(my $fh, &quot;<&quot;, $filename); # No need to check!
  • 89. CPAN!
  • 90. Antes o tratamento de erros era assim
      eval {
        ...algum codigo que pode lançar um erro...
      }; if($@){ # cuidado! $@ é global! :/
        print &quot;opa...&quot;;
      }
  • 91. Try::Tiny
      use Try::Tiny; try {
        algum codigo que pode lançar um erro
      } catch {
        warn &quot;opa... ocorreu um erro $_&quot;;
      } finally {
        ...
      };
  • 92. Moose
  • 93. Perl 5 é Orientado a Objetos!
  • 94. 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}; }
  • 95. Moose is a postmodern object system for Perl 5
  • 96. 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); }
  • 97. 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;
  • 98. Roles
  • 99. package Breakable; use Moose::Role; has 'is_broken' => ( is => 'rw', isa => 'Bool' ); sub break { shift->is_broken(1); }
  • 100. package Car; use Moose; with 'Breakable'; ...
  • 101. Outros Modulos
    • DateTime
    • 102. Smart::Comments
    • 103. IO::All
    • 104. Perl::Tidy
    • 105. Perl::Critic
    • 106. Email::Simple
    • 107. Text::CSV_XS
    • 108. Config::Any
    • DBI
    • 109. Dist::Zilla
    • 110. Devel::NYTProf
    • 111. Devel::Cover
    • 112. Log::Log4Perl
    • 113. POE
    • 114. WWW::Mechanize
    • 115. Task::Kensho
  • 116. 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');
  • 117. Inline::C
      use Inline C => <<'END_C'; void greet() { printf(&quot;Hello, worldn&quot;); } END_C greet; # imprime hello world from C
  • 118. 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;
  • 119.
      Attribute::Overload
      use Attribute::Overload; sub add : Overload(+) { # ... }
  • 120. Template Toolkit
  • 121. DBIx::Class
  • 122. Catalyst
  • 123. Dancer
  • 124. Mojolicious
  • 125. ojo
      perl -Mojo -e '
        a(&quot;/&quot; => {text => &quot;Hello Mojo!&quot;})->start
      ' daemon a : any g : get p : post u : put d : delete
  • 126. 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;
  • 127. 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%>.
  • 128. Mojolicious::Lite
      websocket '/echo' => sub { my $self = shift; $self->on_message(sub { my ($self, $message) = @_; $self->send_message(&quot;echo: $message&quot;); }); };
  • 129. http://mojolicio.us/perldoc
  • 130. Mojolicious
  • 131. mojo generate app MyApp
  • 132. 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
  • 133. 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;
  • 134. 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;
  • 135. 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
  • 136. #!/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);
  • 137. Perl5i
  • 138. Perl 6
  • 139. 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
  • 140. 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
  • 141. Language Reference
    • perlsyn – sintaxe
    • 142. perldata – data types
    • 143. perlsub – subrotinas
    • 144. perlvar – variaveis predefinidas
    • 145. perltie – variaveis “tie”
    • 146. perlport – escrever codigo portavel !
    • 147. perlperf – tecnicas de performance
    • 148. perlmod – modulos e tabela de simbolos
  • 149. Tutoriais
    • perlstyle – style guide
    • 150. perlreftut – references
    • 151. perlretut – regular expressions
    • 152. perlunitut – unicode
    • 153. perllol – arrays of arrays
    • 154. perlopentut – open things
    • 155. perlboot – Beginner's OO
    • 156. perlxstut – sobre XS
  • 157. Obrigado