vergessen und unterschätzt
Transcrição
vergessen und unterschätzt
Perl vergessen und unterschätzt Perl – vergessen und unterschätzt code.talks 2014 / Sebastian Willing print Dumper(\%speaker); ● Sebastian Willing ● CPAN: sewi ● Blog: www.pal-blog.de ● Jahrgang 1979 ● Erste Programmierversuche ~1988 ● Perl seit 1997 ● Padre, the Perl IDE ● Seit 2011 bei ● (und Vorgängern) ● Perl, MovableType, eCommerce, Webdesign, u.v.m. ● www.spark5.de ● [email protected] Privat: 2 Kinder, Buchautor, Hobbypilot Perl – vergessen und unterschätzt code.talks 2014 / Sebastian Willing Perl? Perl – vergessen und unterschätzt code.talks 2014 / Sebastian Willing Niemand nutzt heute noch Perl! (außer Aber wen interessiert das? ) Perl – vergessen und unterschätzt code.talks 2014 / Sebastian Willing Viel interessanter ist... Die meisten Unternehmen nutzen Perl! Schnittstellen Serveradministration Datenkonvertierung Kleine Tools u.v.m. (Aber kaum jemand weiß davon) Perl – vergessen und unterschätzt code.talks 2014 / Sebastian Willing Geschichte Perl history in brief, by Larry Wall: Perl – vergessen und unterschätzt code.talks 2014 / Sebastian Willing Modernes Perl! e l b a 94 t 9 1 s e sin c PSGI/Plack Perl – vergessen und unterschätzt code.talks 2014 / Sebastian Willing Perl 2014 Stabil = „quasi bugfrei“ Plattformunabhängig Einfach erlernbar OOP (freiwillig) RegEx: Mehr als „PCRE“ TIMTOWTDI There is more than one way to do it Abwärtskompatibel Perl – vergessen und unterschätzt code.talks 2014 / Sebastian Willing Perl 2014 CPAN Dancer Moose Data::ObjectDriver Template::Toolkit PSGI/Plack Test::More Perl – vergessen und unterschätzt code.talks 2014 / Sebastian Willing http://search.cpan.org 30.417 Module 138.497 Dateien 11.743 Contributors/Uploaders Standartisierte Installation Systemweit oder im Userverzeichnis Automatische Abhängigkeiten CPAN-Testers Perl – vergessen und unterschätzt code.talks 2014 / Sebastian Willing Dancer Web-Framework Einfach zu lernen flexibel & mächtig Plugins (z.B. Sessioning, Datenbanken, Auth, Ajax, REST, Logging, Gearman, etc.) Standalone, Apache/NGINX, FastCGI, PSGI/Plack, usw. Konzentration auf das Wesentliche Perl – vergessen und unterschätzt code.talks 2014 / Sebastian Willing Dancer: Neue App $ dancer a MyApp The latest stable Dancer release is 1.3130, you are currently Templates using 1.312. Please check http://search.cpan.org/dist/Dancer/ for updates. + MyApp/views/index.tt Standalone-Webserver + MyApp/views/layouts + MyApp/views/layouts/main.tt + MyApp/Makefile.PL Environments + MyApp/bin/app.pl + MyApp/environments/production.yml + MyApp/environments/development.yml Projekt-Config + MyApp/config.yml + MyApp/public Verzeichnis für statische Dateien + MyApp/public/images + MyApp/public/css + MyApp/public/css/style.css Unit-Tests + MyApp/public/javascripts + MyApp/t/001_base.t + MyApp/lib/MyApp.pm App-Modul Perl – vergessen und unterschätzt code.talks 2014 / Sebastian Willing Dancer: Beispiel package MyApp; use strict; use warnings; use Dancer; use MyApp::User; Alle /admin URIs nur für Admins hook 'before' => sub { forward '/' if request>path_info =~ /^\/admin\// /user_info/12345 and !session('is_admin'); }; User via ORM laden get '/user_info/:userid' => sub { my $user = MyApp::User>lookup(param('userid')) or forward '/user_not_found'; template 'user_info.tt', { user => $user }; }; Template & Parameter Perl – vergessen und unterschätzt code.talks 2014 / Sebastian Willing Dancer: Beispiel package MyApp; use strict; use warnings; use Dancer; use MyApp::User; hook 'before' => sub { forward '/' if request>path_info =~ /^\/admin\// and !session('is_admin'); }; get '/user_info/:userid' => sub { template 'user_info.tt', { user => MyApp::User>lookup(param('userid')) or forward '/user_not_found' }; }; Kompakter Perl – vergessen und unterschätzt code.talks 2014 / Sebastian Willing Moose ● Post-modern object system for Perl Erweiterungen für Perl's natives OOP Perl Moose ● use MooseX::Declare; use Method::Signatures::Modifiers; class MyClass { has 'version' => { is => 'ro', isa => 'Str', Default => '1.0', }; method twice (Int $bar) { return 2 * $bar; } } package MyClass; our $VERSION = '1.0'; oder: sub version { return '1.0'; } sub twice { my $self = shift; my $bar = shift; return 2 * $bar; } Perl – vergessen und unterschätzt code.talks 2014 / Sebastian Willing Data::ObjectDriver ● ORM für relationale Datenbanken ● Caching-Support (z.B. Memcache) ● Partitionierung ● Unterstützung für mehrere Datenbanken ● Tabellen-Spalten werden zu Methoden ● Optional zusätzliche Methoden ● Alternativen: z.B. DBIx::Class, Class::DBI, RoseDB Perl – vergessen und unterschätzt code.talks 2014 / Sebastian Willing Template::Toolkit ● Beliebte Perl Template-Engine ● Vielfältig konfigurierbar ● Einfach Erweiterbar ● OOP-Support ● Nicht auf HTML beschränkt ● Templates werden zu Perl-Code kompiliert ● Template-Caching ● Standalone-Tool „ttree“ Perl – vergessen und unterschätzt code.talks 2014 / Sebastian Willing Template::Toolkit - Alternativen ● ● PHP („Perl Hypertext Preprocessor“) – MovableType, Mojolicious, Catalyst u.a. unterstützen PHP als Template-Engine – CPAN-Module „PHP“ und „PHP::eval“ führen PHPSource in Perl aus Text::Clevery – ● Smarty-Implementation in Perl (CPAN) 4907 Template-Module auf CPAN Perl – vergessen und unterschätzt code.talks 2014 / Sebastian Willing PSGI/Plack ● ● Abstraktionslayer für Web-Apps Einheitliche Schnittstelle zwischen Webserver und App ● Inspiriert von Python's WSGI und Ruby's Rack ● Module/Plugins für Apache & Nginx ● Standalone-Webserver (z.B. Starman, Twiggy) ● Unterstützt von (nahezu) allen Perl-Frameworks ● >380 Middleware-Plugins (Logging, Auth, Profiling, Stats, Debugging, Filter, Compress, etc.) Perl – vergessen und unterschätzt code.talks 2014 / Sebastian Willing Test::More ● Wer braucht schon Tests, wir sind doch alle perfekt! ● Test::More – Einfache Unittests in Perl ● Test::WWW::Mechanize – Web-Tests ● Überraschung: ~5000 Test-Module auf CPAN Perl – vergessen und unterschätzt code.talks 2014 / Sebastian Willing Test::More use Test::More tests => 25; Modul compilieren und laden – als Test use_ok('MyApp::SomeModule'); # Compile test ok(my $obj = MyApp::SomeModule>new, 'Create object'); isa_ok($obj, 'MyApp::SomeModule'); Objekt instanzieren note(„Object is $obj“); Debug Meldung 1 == 1 ? is($obj>one, 1, 'Check one'); 1 != 0 ? isnt($obj>one, 0, 'Check not one'); cmp_ok($obj>two, '>', 1, 'Check two'); 2<1? like($obj>answer, qr/^\d\d$/, 'Check answer to all questions'); TODO: { RegEx-Check local $TODO = „will be fixed sometimes or never“; is($obj>pi, 3.1415, 'Pi'); # Currently returns 42 }; Test schlägt fehl = „TODO“ Perl – vergessen und unterschätzt code.talks 2014 / Sebastian Willing Ausprobieren! Windows StrawberryPerl oder ActivePerl Linux (inkl. Mac OS) Vorinstalliert (meist im Distributions-Core) http://strawberryperl.com/ ● Kostenlos ● Inkl. IDE & CPAN-Client IDEs: ● Padre http://padre.perlide.org (kostenlos) ● EPIC (Eclipse-Plugin) ● u.v.a. http://learn.perl.org/ Perl – vergessen und unterschätzt code.talks 2014 / Sebastian Willing Fragen ? Perl – vergessen und unterschätzt code.talks 2014 / Sebastian Willing Vielen Dank fürs zuhören http://www.pal-blog.de [email protected] http://www.spark5.de https://twitter.com/PAL_Blog https://www.facebook.com/sebastian.willing https://plus.google.com/u/0/+SebastianWilling Perl – vergessen und unterschätzt code.talks 2014 / Sebastian Willing