Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
SlideShare a Scribd company logo

1

Author: Mons Anderson (MONS)

2

search.cpan.org/~mons XML-Declare uni-perl AnyEvent-SMTP accessors-fast ex-lib Test-If AnyEvent-RPC Acme-CPANAuthors-AnyEvent constant-def AnyEvent-Worker Image-JpegTran XML-Hash-LX Socket-AcceptFilter XML-Parser-Style-EasyTree lvalue Catalyst-Action-Serialize-XML-Hash-LX XML-Fast Devel-Leak-Cb lib-abs Crypt-RSA-Yandex AnyEvent-Connection AnyEvent-Memcached Test-More-UTF8 Dash-Leak AnyEvent-Handle-Writer Variable-Eject self-init XML-RPC-Fast Image-LibExif Test-Dist

3

github.com/Mons AnyEvent::HTTP::Server AnyEvent::UA AnyEvent-XMPP-2 Proc::Vsize Daemond Devel::Rewrite CatalystX-InternalRedirect

4

use lib ? use lib '../lib'; use lib '/opt/project/lib'; use FindBin; use lib «$FindBin::Bin/../lib»;

5

09.11.2008 ex::lib (now lib::abs) (thanks to A. Shrub ;)

6

use lib::abs (ex::lib) use lib::abs '../lib'; use lib::abs '../../*/lib';

7

use, use, use? use utf8; use strict; use warnings; use Carp; use Data::Dumper; use open qw(:utf8 :std); use mro 'c3'; use feature qw(say state switch);

8

use warnings? Use of uninitialized value...

9

common::sense? - No utf8 until v3.0 - No open :utf8 support for v3.0+ - No require perl 5.10+ for features - No Carp - No mro

10

use uni::perl ':dumper'; use strict; use feature qw(say state switch); no warnings; use warnings qw(FATAL ...); no warnings qw(exec newline); use utf8; use open (:utf8 :std); use mro 'c3'; use autouse 'Carp'; use autouse 'Data::Dumper';

11

Secret feature ;) (pluggable) use uni::perl ':ru'; say cp1251::encode «...»; say cp1251::decode «...»; say koi8r::encode «...»; say koi8r::decode «...»; say cp866::encode «...»; say cp866::decode «...»;

12

XML::* XML::RPC::Fast XML::Parser::Style::EasyTree XML::Hash::LX XML::Fast XML::Declare

13

Test::* Test::Dist kwalitee for cpants.perl.org

14

Test::* Test::If — tired of eval { use Test::...; 1 } or plan skip_all => «...»; $Test::...::VERSION >= 1.23 or plan skip_all => «...»;

15

Test::* Test::More::UTF8 against Wide character in print at Test/Builder.pm line 1698.

16

Fun syntax - lvalue - self::init - accessors-fast - constant-def

17

lvalue sub mysub : lvalue { get { return 'result for get'; } set { my $set_value = shift;   # ... } }

18

self::init use self::init a => qw(a b), b => (), c => qw( c c ), ; vs __PACKAGE__->a(qw(a b)); __PACKAGE__->b(); __PACKAGE__->c(qw(c c));

19

accessors::fast use accessors::fast qw(field1 field2); vs use base 'Class::Accessors::Fast'; __PACKAGE__->mk_accessors( qw(field1 field2) );

20

constant::def use constant::abs 'My::DEBUG' => 1; use constant::def DEBUG => 0; vs BEGIN { *My::DEBUG = sub () { 1 }; } BEGIN { defined &DEBUG or *DEBUG = sub () { 0 }; }

21

AnyEvent::* AnyEvent::Connection manage your connection AnyEvent::SMTP send 7k emails/s AnyEvent::Memcached client with rget (for memcachedb) AnyEvent::Worker any blocking work for AE app AnyEvent::Handle::Writer use sendfile() with write queue AnyEvent::HTTP::Server pipeline, websockets, http/1.1 AnyEvent::UA http/1.1 useragent

22

Image::* Image::JpegTran (binding to jpegtran) Image::LibExif 4000% (40 times) faster than Image::ExifTool

23

Daemond (github) - Correct daemonization - Detach - redirection of output - keeping the fileno for STD* handles - chroot - change user - Pluggable engine - Built-in CLI (Command-line interface) - Pidfile - Scoreboard - Different packages for child and parent - Child monitoring for parent death - Timers for termination

24

Simple Daemond  package SampleD; use Daemond -parent; name 'test'; cli;  # Command line control proc;  # Alter $0 children 1; # How many children pid '/var/run/test.pid'; child { $SIG{USR2} = sub { exit; }; while() { do_job(); } };

25

Daemond CLI Usage: [options] [start|stop|restart|check] Options: -v, --verbose increase verbosity level -f, --nodetach run in nodetach mode -c N, --children N redefine count of children

26

Devel::Rewrite # @rewrite s/^#+//; # use Some::Development::Module; # @rewrite s/some_call/another_call/; $object->some_call; sub something { # @include sub.debug.inc ... } perl -MDevel::Rewrite …

27

Dash-Leak use Dash::Leak; { leaksz "block label"; # some code, that may leak } leaksz "tests begin"; some_operation($arg); leaksz "some_operation", sub { warn sprintf "We leaked by %+d kilobytes;", shift }; $ DEBUG_MEM=1 perl ...

More Related Content

Владимир Перепелица "Модули"

  • 2. search.cpan.org/~mons XML-Declare uni-perl AnyEvent-SMTP accessors-fast ex-lib Test-If AnyEvent-RPC Acme-CPANAuthors-AnyEvent constant-def AnyEvent-Worker Image-JpegTran XML-Hash-LX Socket-AcceptFilter XML-Parser-Style-EasyTree lvalue Catalyst-Action-Serialize-XML-Hash-LX XML-Fast Devel-Leak-Cb lib-abs Crypt-RSA-Yandex AnyEvent-Connection AnyEvent-Memcached Test-More-UTF8 Dash-Leak AnyEvent-Handle-Writer Variable-Eject self-init XML-RPC-Fast Image-LibExif Test-Dist
  • 3. github.com/Mons AnyEvent::HTTP::Server AnyEvent::UA AnyEvent-XMPP-2 Proc::Vsize Daemond Devel::Rewrite CatalystX-InternalRedirect
  • 4. use lib ? use lib '../lib'; use lib '/opt/project/lib'; use FindBin; use lib «$FindBin::Bin/../lib»;
  • 5. 09.11.2008 ex::lib (now lib::abs) (thanks to A. Shrub ;)
  • 6. use lib::abs (ex::lib) use lib::abs '../lib'; use lib::abs '../../*/lib';
  • 7. use, use, use? use utf8; use strict; use warnings; use Carp; use Data::Dumper; use open qw(:utf8 :std); use mro 'c3'; use feature qw(say state switch);
  • 8. use warnings? Use of uninitialized value...
  • 9. common::sense? - No utf8 until v3.0 - No open :utf8 support for v3.0+ - No require perl 5.10+ for features - No Carp - No mro
  • 10. use uni::perl ':dumper'; use strict; use feature qw(say state switch); no warnings; use warnings qw(FATAL ...); no warnings qw(exec newline); use utf8; use open (:utf8 :std); use mro 'c3'; use autouse 'Carp'; use autouse 'Data::Dumper';
  • 11. Secret feature ;) (pluggable) use uni::perl ':ru'; say cp1251::encode «...»; say cp1251::decode «...»; say koi8r::encode «...»; say koi8r::decode «...»; say cp866::encode «...»; say cp866::decode «...»;
  • 12. XML::* XML::RPC::Fast XML::Parser::Style::EasyTree XML::Hash::LX XML::Fast XML::Declare
  • 13. Test::* Test::Dist kwalitee for cpants.perl.org
  • 14. Test::* Test::If — tired of eval { use Test::...; 1 } or plan skip_all => «...»; $Test::...::VERSION >= 1.23 or plan skip_all => «...»;
  • 15. Test::* Test::More::UTF8 against Wide character in print at Test/Builder.pm line 1698.
  • 16. Fun syntax - lvalue - self::init - accessors-fast - constant-def
  • 17. lvalue sub mysub : lvalue { get { return 'result for get'; } set { my $set_value = shift; # ... } }
  • 18. self::init use self::init a => qw(a b), b => (), c => qw( c c ), ; vs __PACKAGE__->a(qw(a b)); __PACKAGE__->b(); __PACKAGE__->c(qw(c c));
  • 19. accessors::fast use accessors::fast qw(field1 field2); vs use base 'Class::Accessors::Fast'; __PACKAGE__->mk_accessors( qw(field1 field2) );
  • 20. constant::def use constant::abs 'My::DEBUG' => 1; use constant::def DEBUG => 0; vs BEGIN { *My::DEBUG = sub () { 1 }; } BEGIN { defined &DEBUG or *DEBUG = sub () { 0 }; }
  • 21. AnyEvent::* AnyEvent::Connection manage your connection AnyEvent::SMTP send 7k emails/s AnyEvent::Memcached client with rget (for memcachedb) AnyEvent::Worker any blocking work for AE app AnyEvent::Handle::Writer use sendfile() with write queue AnyEvent::HTTP::Server pipeline, websockets, http/1.1 AnyEvent::UA http/1.1 useragent
  • 22. Image::* Image::JpegTran (binding to jpegtran) Image::LibExif 4000% (40 times) faster than Image::ExifTool
  • 23. Daemond (github) - Correct daemonization - Detach - redirection of output - keeping the fileno for STD* handles - chroot - change user - Pluggable engine - Built-in CLI (Command-line interface) - Pidfile - Scoreboard - Different packages for child and parent - Child monitoring for parent death - Timers for termination
  • 24. Simple Daemond package SampleD; use Daemond -parent; name 'test'; cli; # Command line control proc; # Alter $0 children 1; # How many children pid '/var/run/test.pid'; child { $SIG{USR2} = sub { exit; }; while() { do_job(); } };
  • 25. Daemond CLI Usage: [options] [start|stop|restart|check] Options: -v, --verbose increase verbosity level -f, --nodetach run in nodetach mode -c N, --children N redefine count of children
  • 26. Devel::Rewrite # @rewrite s/^#+//; # use Some::Development::Module; # @rewrite s/some_call/another_call/; $object->some_call; sub something { # @include sub.debug.inc ... } perl -MDevel::Rewrite …
  • 27. Dash-Leak use Dash::Leak; { leaksz "block label"; # some code, that may leak } leaksz "tests begin"; some_operation($arg); leaksz "some_operation", sub { warn sprintf "We leaked by %+d kilobytes;", shift }; $ DEBUG_MEM=1 perl ...