Your SlideShare is downloading. ×
0
Perl Moderno
Perl Moderno
Perl Moderno
Perl Moderno
Perl Moderno
Perl Moderno
Perl Moderno
Perl Moderno
Perl Moderno
Perl Moderno
Perl Moderno
Perl Moderno
Perl Moderno
Perl Moderno
Perl Moderno
Perl Moderno
Perl Moderno
Perl Moderno
Perl Moderno
Perl Moderno
Perl Moderno
Perl Moderno
Perl Moderno
Perl Moderno
Perl Moderno
Perl Moderno
Perl Moderno
Perl Moderno
Perl Moderno
Perl Moderno
Perl Moderno
Perl Moderno
Perl Moderno
Perl Moderno
Perl Moderno
Perl Moderno
Perl Moderno
Perl Moderno
Perl Moderno
Perl Moderno
Perl Moderno
Perl Moderno
Perl Moderno
Perl Moderno
Perl Moderno
Perl Moderno
Perl Moderno
Perl Moderno
Perl Moderno
Perl Moderno
Perl Moderno
Perl Moderno
Perl Moderno
Perl Moderno
Perl Moderno
Perl Moderno
Perl Moderno
Perl Moderno
Perl Moderno
Perl Moderno
Perl Moderno
Perl Moderno
Perl Moderno
Perl Moderno
Perl Moderno
Perl Moderno
Perl Moderno
Perl Moderno
Perl Moderno
Perl Moderno
Perl Moderno
Perl Moderno
Perl Moderno
Perl Moderno
Perl Moderno
Perl Moderno
Perl Moderno
Perl Moderno
Perl Moderno
Perl Moderno
Perl Moderno
Perl Moderno
Perl Moderno
Perl Moderno
Perl Moderno
Perl Moderno
Perl Moderno
Perl Moderno
Perl Moderno
Perl Moderno
Perl Moderno
Perl Moderno
Perl Moderno
Perl Moderno
Perl Moderno
Perl Moderno
Perl Moderno
Perl Moderno
Perl Moderno
Perl Moderno
Perl Moderno
Perl Moderno
Perl Moderno
Perl Moderno
Perl Moderno
Perl Moderno
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Perl Moderno

4,524

Published on

Apresentação sobre Perl Moderno no III FSLDC

Apresentação sobre Perl Moderno no III FSLDC

Published in: Technology
1 Comment
0 Likes
Statistics
Notes
  • Be the first to like this

No Downloads
Views
Total Views
4,524
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
18
Comments
1
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

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. $==$'; $;||$.| $|;$_ ='*$ ( ^@(%_+&~~;# ~~/.~~ ;_);;.);;#) ;~~~~;_,.~~,.* +,./|~ ~;_);@-, .;.); ~ ~,./@@-__);@-);~~,.*+,. /|);;;~~@-~~~~;;(),. ;.,./@,./@,.;_~~@-););,. ;_);~~,./@,.;;;./@,./ |~~~~;#-(@-__@-__&$#%^';$__ ='`'&'&';$___="````" |"$[`$["|'`%",';$~=("$___$__-$[``$__"| "$___"| ("$___$__-$[.%")).("'`"|"'$["|"'#"). '/.*?&([^&]*)&.*/$'.++$=.("/``"|"/$[`"|"/#'").(";`/[``$__]//`;" |";$[/[$[`$__]//`;"|";#/[$.$__]//'").'@:=("@-","/.", "~~",";#",";;",";.",",.",");","()","*+","__","-(","/@",".%","/|", ";_");@:{@:}=$%..$#:;'.('`'|"$["|'#')."/(..)(..)/".("```"|"``$["| '#("').'(($:{$'.$=.'}<<'.(++$=+$=).')|($:{$'.$=.'}))/'.("```;"| "``$[;"|"%'#;").("````'$__"|"%$[``"|"%&!,").${$[};`$~$__>&$=`;$_= '*$(^@(%_+&@-__~~;#~~@-;.;;,.(),./.,./|,.-();;#~~@-);;;,.;_~~@-,./., ./@,./@~~@-);;;,.(),.;.~~@-,.,.,.;_,./@,.-();;#~~@-,.;_,./|~~@-,. ,.);););@-@-__~~;#~~@-,.,.,.;_);~~~~@-);;;,.(),.*+);;# ~~@-, ./|,.*+,.,.);;;);*+~~@-,.*+,.;;,.;.,./.~~@-,.,.,.;_) ;~~~ ~@-,.;;,.;.,./@,./.);*+,.;.,.;;@-__~~;#~~@-,.;;,.* +);; #);@-,./@,./.);*+~~@-~~.%~~.%~~@-;;__,. /.);;#@- [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"
  • 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. <ul>The feature pragma </ul>
  • 49. <ul>use feature “:5.10”; use feature qw( … ); </ul>
  • 50. Antes eu tinha que fazer assim <ul>#!/usr/bin/perl use strict; use warnings; print “hello worldn”; # argh... não posso esquecer o n no final! </ul>
  • 51. Agora podemos escrever <ul>#!/usr/bin/perl use strict; use warnings; use feature &apos;say&apos;; say “hello world”; </ul>
  • 52. Modern::Perl <ul><li>#!/usr/bin/perl
  • 53. use Modern::Perl;
  • 54. # precisa instalar via CPAN...
  • 55. say “hello world”; </li></ul>
  • 56. Modern::Perl <ul><li>Operador //
  • 57. Given/ When
  • 58. State variables
  • 59. Smart Matching ~~
  • 60. Regular Expression (?&lt;name&gt;...)
  • 61. Pragma mro for Method Resolution Order </li><ul><li>DFS Depth First Search
  • 62. C3 (like Dylan language) </li></ul></ul>
  • 63. Implicit Strictures in Perl 5.12 <ul>use 5.12.0; significa: use strict; use feature &apos;:5.12&apos;; </ul>
  • 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 <ul>Package Foo::Bar 1.2 { # code } </ul>
  • 70. Filehandle method calls load IO::File on demand <ul>open my $fh, &amp;quot;&gt;&amp;quot;, $file; # loads IO::File and succeeds $fh-&gt;autoflush(1); # local $| = 1; $fh-&gt;binmode(&amp;quot;:raw&amp;quot;); $fh-&gt;close; </ul>
  • 71. Modulos Core (alguns...) <ul><li>Carp
  • 72. Data::Dumper
  • 73. Encode
  • 74. English
  • 75. File::Temp
  • 76. Findbin
  • 77. Getopt::Long
  • 78. Scalar::Util </li></ul><ul><li>List::Util
  • 79. Hash::Util
  • 80. Memoize
  • 81. Module::Pluggable
  • 82. Test::Simple
  • 83. Test::More
  • 84. Tie::File
  • 85. Time::HiRes </li></ul>
  • 86. autodie <ul>Antes: open(my $fh,&amp;quot;&lt;&amp;quot;,$filename) <ul>or die &amp;quot;ops...&amp;quot;; </ul></ul>
  • 87. autodie <ul>bIlujDI&apos; yIchegh()Qo&apos;; yIHegh()! It is better to die() than to return() in failure. -- Klingon programming proverb. </ul>
  • 88. autodie <ul>use autodie qw(open close); # open/close succeed or die open(my $fh, &amp;quot;&lt;&amp;quot;, $filename); # No need to check! </ul>
  • 89. CPAN!
  • 90. Antes o tratamento de erros era assim <ul>eval { <ul>...algum codigo que pode lançar um erro... </ul>}; if($@){ # cuidado! $@ é global! :/ <ul>print &amp;quot;opa...&amp;quot;; </ul>} </ul>
  • 91. Try::Tiny <ul>use Try::Tiny; try { <ul>algum codigo que pode lançar um erro </ul>} catch { <ul>warn &amp;quot;opa... ocorreu um erro $_&amp;quot;; </ul>} finally { <ul>... </ul>}; </ul>
  • 92. Moose
  • 93. Perl 5 é Orientado a Objetos!
  • 94. package Point; sub new { # construtor! my $klass = shift ; my $self = { x =&gt; 0, y =&gt; 0}; bless $self, $klass; } # criando um acessor para a prop. x sub x { my $self = shift ; my $x = shift ; $self-&gt;{x} = $x // $self-&gt;{x}; }
  • 95. Moose is a postmodern object system for Perl 5
  • 96. package Point; use Moose; has &apos;x&apos; =&gt; (is =&gt; &apos;rw&apos;, isa =&gt; &apos;Int&apos;); has &apos;y&apos; =&gt; (is =&gt; &apos;rw&apos;, isa =&gt; &apos;Int&apos;); sub clear { my $self = shift; $self-&gt;x(0); $self-&gt;y(0); }
  • 97. package Point3D; use Moose; extends &apos;Point&apos;; has &apos;z&apos; =&gt; (is =&gt; &apos;rw&apos;, isa =&gt; &apos;Int&apos;); after &apos;clear&apos; =&gt; sub { my $self = shift; $self-&gt;z(0); } __PACKAGE__-&gt;meta-&gt;make_immutable;
  • 98. Roles
  • 99. package Breakable; use Moose::Role; has &apos;is_broken&apos; =&gt; ( is =&gt; &apos;rw&apos;, isa =&gt; &apos;Bool&apos; ); sub break { shift-&gt;is_broken(1); }
  • 100. package Car; use Moose; with &apos;Breakable&apos;; ...
  • 101. Outros Modulos <ul><li>DateTime
  • 102. Smart::Comments
  • 103. IO::All
  • 104. Perl::Tidy
  • 105. Perl::Critic
  • 106. Email::Simple
  • 107. Text::CSV_XS
  • 108. Config::Any </li></ul><ul><li>DBI
  • 109. Dist::Zilla
  • 110. Devel::NYTProf
  • 111. Devel::Cover
  • 112. Log::Log4Perl
  • 113. POE
  • 114. WWW::Mechanize
  • 115. Task::Kensho </li></ul>
  • 116. Shell <ul>use Shell qw(cat ps cp); $passwd = cat(&apos;&lt;/etc/passwd&apos;); @pslines = ps(&apos;-ww&apos;); cp(&amp;quot;/etc/passwd&amp;quot;, &amp;quot;/tmp/passwd&amp;quot;); # Forma OO, utilizando “method missing” my $sh = Shell-&gt;new; print $sh-&gt;ls(&apos;-l&apos;); </ul>
  • 117. Inline::C <ul>use Inline C =&gt; &lt;&lt;&apos;END_C&apos;; void greet() { printf(&amp;quot;Hello, worldn&amp;quot;); } END_C greet; # imprime hello world from C </ul>
  • 118. Attribute::Util <ul>use Attribute::Memoize; sub fib :Memoize { my $n = shift; return $n if $n &lt; 2; fib($n-1) + fib($n-2); } say fib($_) for 1..50; </ul>
  • 119. <ul>Attribute::Overload </ul><ul>use Attribute::Overload; sub add : Overload(+) { # ... } </ul>
  • 120. Template Toolkit
  • 121. DBIx::Class
  • 122. Catalyst
  • 123. Dancer
  • 124. Mojolicious
  • 125. ojo <ul>perl -Mojo -e &apos; <ul>a(&amp;quot;/&amp;quot; =&gt; {text =&gt; &amp;quot;Hello Mojo!&amp;quot;})-&gt;start </ul>&apos; daemon a : any g : get p : post u : put d : delete </ul>
  • 126. Mojolicious::Lite <ul>use Mojolicious::Lite; # Route with placeholder get &apos;/:foo&apos; =&gt; sub { my $self = shift; my $foo = $self-&gt;param(&apos;foo&apos;); $self-&gt;render(text =&gt; &amp;quot;Hello from $foo!&amp;quot;); }; # Start the Mojolicious command system app-&gt;start; </ul>
  • 127. Mojolicious::Lite <ul># /foo?user=bar get &apos;/foo&apos; =&gt; sub { my $self = shift; my $user = $self-&gt;param(&apos;user&apos;); $self-&gt;stash(one =&gt; 23); $self-&gt;render(&apos;baz&apos;, two =&gt; 24, u =&gt; $user); }; __DATA__ @@ baz.html.ep Hello &lt;%=$u%&gt; with &lt;%=$one%&gt; and &lt;%=$two%&gt;. </ul>
  • 128. Mojolicious::Lite <ul>websocket &apos;/echo&apos; =&gt; sub { my $self = shift; $self-&gt;on_message(sub { my ($self, $message) = @_; $self-&gt;send_message(&amp;quot;echo: $message&amp;quot;); }); }; </ul>
  • 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 &apos;Mojolicious&apos;; # This method will run once at server start sub startup { my $self = shift; # Documentation browser under &amp;quot;/perldoc&amp;quot; $self-&gt;plugin(&apos;pod_renderer&apos;); # Routes my $r = $self-&gt;routes; # Normal route to controller $r-&gt;route(&apos;/welcome&apos;)-&gt;to(&apos;example#welcome&apos;); } 1;
  • 134. package MyApp::Example; use Mojo::Base &apos;Mojolicious::Controller&apos;; # This action will render a template sub welcome { my $self = shift; # Render template &amp;quot;example/welcome.html.ep&amp;quot; # with message $self-&gt;render(message =&gt; &apos;Welcome to the Mojolicious Web Framework!&apos;); } 1;
  • 135. templates/layouts/default.htmp.ep &lt;!doctype html&gt;&lt;html&gt; &lt;head&gt;&lt;title&gt;&lt;%= title %&gt;&lt;/title&gt;&lt;/head&gt; &lt;body&gt;&lt;%= content %&gt;&lt;/body&gt; &lt;/html&gt; templates/example/welcome.html.ep % layout &apos;default&apos;; % title &apos;Welcome&apos;; &lt;h2&gt;&lt;%= $message %&gt;&lt;/h2&gt; This page was generated from the template
  • 136. #!/usr/bin/env perl use strict; use warnings; use Test::More tests =&gt; 5; use Test::Mojo; use_ok &apos;MyApp&apos;; # Test my $t = Test::Mojo-&gt;new(app =&gt; &apos;MyApp&apos;); $t-&gt;get_ok(&apos;/welcome&apos;)-&gt;status_is(200) -&gt;content_type_is(&apos;text/html;charset=UTF-8&apos;) -&gt;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 <ul><li>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 </li></ul>
  • 149. Tutoriais <ul><li>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&apos;s OO
  • 156. perlxstut – sobre XS </li></ul>
  • 157. Obrigado

×