cpan 模組二三事

Post on 08-May-2015

4.150 Views

Category:

Documents

6 Downloads

Preview:

Click to see full reader

DESCRIPTION

CPAN 模組

TRANSCRIPT

CPAN 模組二三事c9s (cornelius)

http://github.com/c9scornelius.howl@gmail.com

什麼是 CPAN 模組

• DRY ( Dont repeat yourself)

• Class Library

• 3400+ authors

• 12000+ modules

• Unit Tests

CPAN 文化

CPAN 異像 ?

Release Often

Unit Testing

Module review

Write OnceNever Maintain (?)

寫一次,從不維護 XD

Read-only 的 Module ?

Patch 無效,Please patch locally.... XD

文件隨意寫不寫也可以 (小聲)

模組名稱可預購!

寫空的也行 XD

別緊張

她,我可以.... (blush)

以上全部不是事實

好的

好的,髒的

好的,髒的,糟糕的

以及 怪怪的

全都在 CPAN

CPAN Module 台灣作者群

• audreyt (autrijus)

• gugod

• clkao

• clsung

• imacat

• shelling

• BlueT

• cornelius (c9s)

• etc...

CPAN Module Authors

in TaiwanAcme::CPANAuthors::Taiwanese

• ADAMK (218+ 模組)

• RJBS (211+ 模組)

• Miyagawa ( 177+ 模組)

• CPAN Leaderboard

http://thegestalt.org/simon/perl/wholecpan.html

其他

如何開始

模組安裝步驟

• $ wget http://path/to/Dist-{version}.tar.gz

• $ perl Makefile.PL # 產生 Makefile

• $ make

• $ make install

CPAN 模組工具

• CPAN Shell

• CPANPLUS Shell

• cpanminus

http://github.com/miyagawa/cpanminus

CPAN Shell

• 所有 Unix-like platform 內建

• 初次設定繁雜• 用法: $ cpan [Module Name]

CPANPLUS

• 為了改進 CPAN Shell 而出現

CPANPLUS

• 為了改進 CPAN Shell 而出現

• 結果又比 CPAN Shell 更肥 XD

CPANPLUS

• 為了改進 CPAN Shell 而出現

• 結果又比 CPAN Shell 更肥 XD

• 模組相依性太重

cpanminus

• 無模組相依• 裝了就上• 速度快• 支援無系統權限安裝 (無須繁瑣設定)

cpanminushttp://github.com/miyagawa/cpanminus

$ cd ~/bin/$ wget http://xrl.us/cpanm$ chmod +x cpanm

安裝 CPANMinus

$ git clone git://github.com/miyagawa/cpanminus.git$ cd cpanminus$ perl Makefile.PL$ make install

安裝 CPANMinusfrom github

$ cpanm [Module Name]

$ cpanm -n [Module Name]{no test}

$ cpanm -v [Module Name]{verbose}

$ cpanm -f [Module Name]{force}

$ cpanm --help{help}

cpanm CGI cpanm MIYAGAWA/Plack-0.99_05.tar.gz cpanm http://example.org/LDS/CGI.pm-3.20.tar.gz cpanm ~/dists/MyCompany-Enterprise-1.00.tar.gz cpanm --interactive Task::Kensho cpanm . cpanm --installdeps .

其他用法

使用模組

使用模組• 使用 Perldoc 查詢模組文件:

$ perldoc Data::Dumper

• 使用 search.cpan.org 查詢模組文件

• 讀 Synopsis

• 在 Code 使用 use 關鍵字: use Data::Dumper;

模組概覽

Shell

• Getopt::Long - 用以取得 Command Line 參數

• $ getopt.pl --take=blah --id=10 --verbose -t

Shell

• Pod::Usage - 用以針對命令列參數提供文件 my %options = ( debug => 0, );

GetOptions(\%options, qw{ help|h! version|V! debug|d! config|c=s }) or pod2usage(0);

pod2usage({ -verbose => 2, -exitval => 0, -noperldoc => 1 }) if $options{help};

Process

• Proc::Daemon

• ForkManager

• IPC::Run

Lists

• List::Util ( first max maxstr min minstr reduce shuffle sum )

• List::MoreUtils ( any all none notall true false firstidx first_index lastidx last_index insert_after insert_after_string apply after after_incl before before_incl indexes firstval first_value lastval last_value each_array each_arrayref pairwise natatime mesh zip uniq minmax )

Event

• AnyEvent::*

• POE::*

Serialization

• Data::Dumper

• Storable

• JSON (JSON::PP, JSON::XS ...)

• YAML (YAML::XS, YAML::Syck)

Web (server-side)

• AnyEvent::HTTPD

• Plack

• Catalyst , Jifty , Mojo

• Template::Declare , Template::Markpl

• Mason

Web (client-side)

• LWP::UserAgent

• LWP::Simple

• AnyEvent::HTTP

• LWP::Parallel

• HTTP::Async

Web (client-side)

• Web::Scraper

• pQuery

• WWW::Mechanize

• HTTP::Async

HTML

• HTML::Parser

• HTTP::TreeBuilder

• WebService::Validator::HTML::W3C

Documents

• Office

• Spreadsheet::WriteExcel, Spreadsheet::ParseExcel ...

• OpenOffice::*

• PDF::API2

Graphics

• GD, Imager

• Image::Magick

• Gimp

• Cairo

• GraphViz

• Image::LibRSVG

• SVG::Graph

Network

• Protocols

• Net::FTP , Net::SSH, Net::SCP, Net::DNS,

• Net::DHCP , Net::Ping ....

• Low level

• IO::Socket, Net::Packet, Net::Pcap ...

Database

• DBI (PostgreSQL, SQLite, Oracle, MySQL ...)

• DBI::Proxy, DBD::Gofer

• DBIx::Simple

ORM

• Class::DBI, DBIx::Class

• Jifty::DBI

• Prophet

• Tangram, Alzabo, SPOPS

• Rose::DB::Object, DBIx::DataModel, Fey::ORM

Tests

• Test::More, Test::BuilderDevel::CoverTest::Deep, Test::LongStringTest::Exception, Test::NoWarningsTest::MockModule, Test::MockObjectTest::Class, Test::UnitTest::LectroTest

工具

• Module::Starter

• App::Ack

• Perl::Tidy

• Perl::Tags

Debugging

• XXX

• Devel::SimpleTrace

• Devel::Graph

• Devel::LeakTrace

• Devel::NYTProf

Cache

• Cache::CHI

• Cache::Memory

• Cache::File

• Cache::Memcached

Object-oriented Programming

• Class::MOP

• Moose

• Mouse

• autobox

The External World

• Languages

• Inline: C , Java, Ruby, Python ...

• External Library

• XS

• Devel::PPPort

• Swig

• etc...

其他

• Git

• Github::Import

• Gearman

• ....

相關資源

• The Phalanx 100: http://qa.perl.org/phalanx/100/

• CPAN Search: http://search.cpan.org/

• Perldoc: http://www.perldoc.org

• Perl Cookbook

Perlbuzz.com

撰寫模組

• Module::Starter $ module-starter --mi --module=Foo::Bar \ --author=”Your Name” --email=your_email@blah.com

• 編寫模組 lib/Foo/Bar.pm

• 編寫測試 t/*.t

• 編寫 Makefile.PL

撰寫模組• 產生 Makefile , 測試 , 打包:

$ perl Makefile.PL $ make test $ make dist

• 申請 PAUSE ID ( http://pause.perl.org):

• 上傳模組 (CPAN::Uploader) $ make upload ... or $ cpan-upload Dist-0.01.tar.gz

如果您看到這頁代表簡報沒做完...

所以現在是 Live Demo 時間 XD

答客問時間

Thanks/c9s/

top related