| extra_vars1 : | |
|---|---|
| extra_vars2 : |
펄(Perl)의 창시자인 래리 월(Larry Wall)은 “펄은 쉬운 작업은 쉽게, 어려운 작업은 가능하게 한다.” 라고 말했습니다. 실제로 펄을 사용하면 여러분은 대부분의 작업을 정말 쉽고 빠르게 처리할 수 있습니다. 그렇지만 데이터베이스에 접근한다거나, GUI 개발, 웹 개발은 아무리 펄을 사용한다 할지라도 쉬운일이 아닙니다. 물론 이것은 여러분이 CPAN을 발견하기 전 까지의 이야기입니다. 놀랍게도 CPAN은 어려운 작업도 쉽게 처리할 수 있게 도와줍니다. 이 문서에서는 CPAN을 간략하게 소개하고, CPAN을 이용해서 모듈을 찾는 방법, 설치하는 방법, 사용하는 방법을 설명합니다.
CPAN은 “The Comprehensive Perl Archive Network”의 약자입니다. 단어의 뜻 그대로 번역한다면 “네트워크상의 포괄적인 펄의 자료 보관소” 정도가 되겠습니다. CPAN의 기본 주소(primary gateway)는 http://www.cpan.org 입니다. CPAN에는 정말 다양한 펄 자료들이 존재합니다. 이곳에는 펄 그 자체를 비롯하여 모듈들과 스크립트, 문서자료가 존재합니다. 또한 이곳의 모든 자료는 오픈소스이며, 자유롭게 다운로드 및 이용이 가능하며, 원하는 기능을 개선해서 커밋(commit), 및 기여(contribut)를 할 수 있습니다. 데이터베이스 접근 및 다양한 GUI 바인딩, 생명공학, OpenGL, GD 라이브러리 등 필요한 거의 모든 자료가 존재합니다. CPAN은 1995년 10월 26일에 첫 선을 보인 후 2007년 2월 현재 3436MB 264 mirrors 5677 authors 11174 modules 의 방대한 양을 자랑하고 있습니다.
CPAN은 단순한 저장소 이상의 펄 커뮤니티입니다. CPAN의 모듈은 오픈소스 라이센스로 릴리즈 되고 활발히 모듈들의 개발이 이루어집니다. CPAN의 메일링 리스트를 이용하여 수백명의 구독자들과 개발을 하고 있습니다. CPAN의 번영은 자진해서 시간과 에너지를 기여하는 프로그래머들 덕분입니다. 여러분은 수많은 능력있는 프로그래머들이 무료로(for free) 기꺼이 작업을 하는 사실에 놀랄 것입니다. 심지어 어떤 CPAN 프로그래머는 실제로 그들의 시간을 기부하는 것이 아니라, CPAN 모듈을 위해 일을 하고 있기도 합니다!
시간이 있다면 여유롭게 CPAN(http://www.cpan.org)를 둘러보면서 필요한 모듈들을 찾을 수도 있고, perldoc을 온라인으로 볼 수도 있으며, 유용한 Perl FAQ도 볼 수 있습니다. CPAN을 처음 사용해본다면 http://www.cpan.org/modules 의 모듈 섹션에서 시작 해볼 것을 추천합니다. 그러나 여러분은 아마 당장 필요한 무엇인가를 찾고 싶을 것입니다. 그렇다면 http://search.cpan.org 로 접속해서 검색을 수행할 수 있습니다. 예를 들어 Gtk2 모듈을 찾고 싶다면 gtk2로 검색하면 됩니다.
또한 C/C++ 라이브러리를 이용한 모듈들을 설치할 경우도 있으니 즐겨 사용하는 C 컴파일러와 C++ 컴파일러도 함께 설치하도록 합니다.
펄에서 기본으로 제공하는 CPAN 모듈을 이용하면 모듈을 인터넷을 통해 다운로드 받고, 의존성을 검사하고, 빌드를 하고, 테스트를 한 후 설치까지의 작업을 자동으로 처리해줍니다. 단 이 방법을 이용하기 위해서는 루트 권한이 있어야 합니다. 방법은 다음과 같습니다:
# cpan
만약 위의 cpan 프로그램이 존재하지 않는다면:
# perl -MCPAN -e shell
위의 두 가지 방법은 동일한 작업을 수행합니다.
만약 여러분이 cpan을 처음 실행하신다면 다음과 같은 메시지를 볼 수 있습니다. 대부분의 경우 적절한 값을 설정하므로 엔터를 눌러 기본 값으로 설정합니다. 단 중간의 지역을 고르는 곳이 있는데 미러 사이트를 설정하기 위한 곳이므로 이 부분만 아시아를 선택한 다음 한국을 선택하도록 합니다:
The following questions are intended to help you with the
configuration. The CPAN module needs a directory of its own to cache
important index files and maybe keep a temporary mirror of CPAN files.
This may be a site-wide directory or a personal directory.
I see you already have a directory
/home/keedi/.cpan
Shall we use it as the general CPAN build and cache directory?
CPAN build and cache directory? [/home/keedi/.cpan]
Unless you are accessing the CPAN via the filesystem directly CPAN.pm
needs to keep the source files it downloads somewhere. Please supply a
directory where the downloaded files are to be kept. [/home/keedi/.cpan/sources]
Directory where the build process takes place? [/home/keedi/.cpan/build]
How big should the disk cache be for keeping the build directories
with all the intermediate files?
Cache size for build directory (in MB)? [10]
The CPAN indexes are usually rebuilt once or twice per hour, but the
typical CPAN mirror mirrors only once or twice per day. Depending on
the quality of your mirror and your desire to be on the bleeding edge,
you may want to set the following value to more or less than one day
(which is the default). It determines after how many days CPAN.pm
downloads new indexes.
Let the index expire after how many days? [1]
By default, each time the CPAN module is started, cache scanning is
performed to keep the cache size in sync. To prevent this, answer
'never'.
Perform cache scanning (atstart or never)? [atstart]
To considerably speed up the initial CPAN shell startup, it is
possible to use Storable to create a cache of metadata. If Storable
is not available, the normal index mechanism will be used.
Cache metadata (yes/no)? [yes]
The CPAN module can detect when a module which you are trying to build
depends on prerequisites. If this happens, it can build the
prerequisites for you automatically ('follow'), ask you for
confirmation ('ask'), or just ignore them ('ignore'). Please set your
policy to one of the three values.
Policy on building prerequisites (follow, ask or ignore)? [ask]
CPAN packages can be digitally signed by authors and thus verified
with the security provided by strong cryptography. The exact mechanism
is defined in the Module::Signature module. While this is generally
considered a good thing, it is not always convenient to the end user
to install modules that are signed incorrectly or where the key of the
author is not available or where some prerequisite for
Module::Signature has a bug and so on.
With the check_sigs parameter you can turn signature checking on and
off. The default is off for now because the whole tool chain for the
functionality is not yet considered mature by some. The author of
CPAN.pm would recommend setting it to true most of the time and
turning it off only if it turns out to be annoying.
Note that if you do not have Module::Signature installed, no signature
checks will be performed at all.
Always try to check and verify signatures if a SIGNATURE file is in the package
and Module::Signature is installed (yes/no)? [no]
The goal of the CPAN Testers project (http://testers.cpan.org/) is to
test as many CPAN packages as possible on as many platforms as
possible. This provides valuable feedback to module authors and
potential users to identify bugs or platform compatibility issues and
improves the overall quality and value of CPAN.
One way you can contribute is to send test results for each module
that you install. If you install the CPAN::Reporter module, you have
the option to automatically generate and email test reports to CPAN
Testers whenever you run tests on a CPAN package.
See the CPAN::Reporter documentation for additional details and
configuration settings. If your firewall blocks outgoing email,
you will need to configure CPAN::Reporter before sending reports.
Email test reports if CPAN::Reporter is installed (yes/no)? [no]
The CPAN module will need a few external programs to work properly.
Please correct me, if I guess the wrong path for a program. Don't
panic if you do not have some of them, just press ENTER for those. To
disable the use of a program, you can type a space followed by ENTER.
Where is your bzip2 program? [/bin/bzip2]
Where is your gzip program? [/bin/gzip]
Where is your tar program? [/bin/tar]
Where is your unzip program? [/usr/bin/unzip]
Where is your make program? [/usr/bin/make]
Where is your curl program? [/usr/bin/curl]
Where is your lynx program? [/usr/bin/lynx]
Where is your wget program? [/usr/bin/wget]
Where is your ncftpget program? [/usr/bin/ncftpget]
Where is your ftp program? [/usr/bin/ftp]
Where is your gpg program? [/usr/bin/gpg]
What is your favorite pager program? [/usr/bin/less]
What is your favorite shell? [/bin/bash]
When you have Module::Build installed and a module comes with both a
Makefile.PL and a Build.PL, which shall have precedence? The two
installer modules we have are the old and well established
ExtUtils::MakeMaker (for short: EUMM) which uses the Makefile.PL and
the next generation installer Module::Build (MB) works with the
Build.PL.
In case you could choose, which installer would you prefer (EUMM or MB)? [EUMM]
Every Makefile.PL is run by perl in a separate process. Likewise we
run 'make' and 'make install' in separate processes. If you have
any parameters (e.g. PREFIX, LIB, UNINST or the like) you want to
pass to the calls, please specify them here.
If you don't understand this question, just press ENTER.
Parameters for the 'perl Makefile.PL' command?
Typical frequently used settings:
PREFIX=~/perl # non-root users (please see manual for more hints)
Your choice: [INSTALLDIRS=site]
Parameters for the 'make' command?
Typical frequently used setting:
-j3 # dual processor system
Your choice: []
Do you want to use a different make command for 'make install'?
Cautious people will probably prefer:
su root -c make
or
sudo make
or
/path1/to/sudo -u admin_account /path2/to/make
or some such. Your choice: [/usr/bin/make]
Parameters for the 'make install' command?
Typical frequently used setting:
UNINST=1 # to always uninstall potentially conflicting files
Your choice: []
The next questions deal with Module::Build support.
A Build.PL is run by perl in a separate process. Likewise we run
'./Build' and './Build install' in separate processes. If you have any
parameters you want to pass to the calls, please specify them here.
Parameters for the 'perl Build.PL' command?
Typical frequently used settings:
--install_base /home/xxx # different installation directory
Your choice: []
Parameters for the './Build' command?
Setting might be:
--extra_linker_flags -L/usr/foo/lib # non-standard library location
Your choice: []
Do you want to use a different command for './Build install'?
Sudo users will probably prefer:
su root -c ./Build
or
sudo ./Build
or
/path1/to/sudo -u admin_account ./Build
or some such. Your choice: [./Build]
Parameters for the './Build install' command?
Typical frequently used setting:
--uninst 1 # uninstall conflicting files
Your choice: []
Sometimes you may wish to leave the processes run by CPAN alone
without caring about them. Because the Makefile.PL or the Build.PL
sometimes contains question you're expected to answer, you can set a
timer that will kill a 'perl Makefile.PL' process after the specified
time in seconds.
If you set this value to 0, these processes will wait forever. This is
the default and recommended setting.
Timeout for inactivity during {Makefile,Build}.PL? [0]
If you're accessing the net via proxies, you can specify them in the
CPAN configuration or via environment variables. The variable in
the $CPAN::Config takes precedence.
Your ftp_proxy? []
Your http_proxy? []
Your no_proxy? []
Shall we always set FTP_PASSIVE envariable when dealing with ftp
download (yes/no)? [yes]
CPAN.pm changes the current working directory often and needs to
determine its own current working directory. Per default it uses
Cwd::cwd but if this doesn't work on your system for some reason,
alternatives can be configured according to the following table:
cwd Cwd::cwd
getcwd Cwd::getcwd
fastcwd Cwd::fastcwd
backtickcwd external command cwd
Preferred method for determining the current working directory? [cwd]
The prompt of the cpan shell can contain the current command number
for easier tracking of the session or be a plain string. Do you want
the command number in the prompt (yes/no)? [yes]
When using Term::ReadLine, you can turn ornaments on so that your
input stands out against the output from CPAN.pm. Do you want to turn
ornaments on? [yes]
When you have Term::ANSIColor installed, you can turn on colorized
output to have some visual differences between normal CPAN.pm output,
warnings, and the output of the modules being installed. Set your
favorite colors after some experimenting with the Term::ANSIColor
module. Do you want to turn on colored output? [no]
Your terminal expects ISO-8859-1 (yes/no)?
The next option deals with the charset (aka character set) your
terminal supports. In general, CPAN is English speaking territory, so
the charset does not matter much, but some of the aliens out there who
upload their software to CPAN bear names that are outside the ASCII
range. If your terminal supports UTF-8, you should say no to the next
question. If it supports ISO-8859-1 (also known as LATIN1) then you
should say yes. If it supports neither, your answer does not matter
because you will not be able to read the names of some authors
anyway. If you answer no, names will be output in UTF-8.
Your terminal expects ISO-8859-1 (yes/no)? [yes]
If you have one of the readline packages (Term::ReadLine::Perl,
Term::ReadLine::Gnu, possibly others) installed, the interactive CPAN
shell will have history support. The next two questions deal with the
filename of the history file and with its size. If you do not want to
set this variable, please hit SPACE RETURN to the following question.
File to save your history? [/home/keedi/.cpan/histfile]
Number of lines to save? [100]
The 'd' and the 'm' command normally only show you information they
have in their in-memory database and thus will never connect to the
internet. If you set the 'show_upload_date' variable to true, 'm' and
'd' will additionally show you the upload date of the module or
distribution. Per default this feature is off because it may require a
net connection to get at the upload date.
Always try to show upload date with 'd' and 'm' command (yes/no)? [yes]
Autoconfigured everything but 'urllist'.
Please call 'o conf init urllist' to configure your CPAN server(s) now!
commit: wrote '/etc/perl/CPAN/Config.pm'
cpan[1]>
위의 설정 과정이 끝났다면 여러분은 cpan 프롬프트를 보게 될 것입니다. 리스트 관련 모듈을 검색하고 싶다면 다음과 같이 입력합니다:
cpan[2]> i /List/
검색 결과를 확인한 후 설치할 모듈의 정보를 정확하게 알기 위해서는 다음과 같이 입력합니다:
cpan[3]> i List::MoreUtil
모든 확인이 끝난 후 설치하기 위해서는 다음의 명령어를 입력합니다:
cpan[4]> install List::MoreUtil
cpan 프로그램을 종료하려면 “exit”를, 도움말을 보고 싶다면 “help”를 입력합니다.
대부분의 경우 쉬운 방법으로 설치를 할 수 있지만 루트 계정을 가지고 있지 않다던가, 설치 과정에 문제가 있어서 위의 방법으로 설치를 할 수 없는 경우가 있습니다. 이 경우는 직접 수동으로 설치를 해야 합니다. 하지만 이 경우도 그렇게 어렵지는 않습니다. CPAN에서 제공하는 모든 모듈은 아래서 설명하는 다운로드, 압축 해제, 빌드, 테스트, 설치의 과정을 통해 설치할 수 있습니다.
$ gzip -dc ModuleNameHere.tar.gz | tar xvf -
$ perl Makefile.pl
$ make
$ make test
# make install
모듈의 설치가 실패하는 경우 중 가장 많은 비율을 차지하는 경우는 C나 C++과의 연동 모듈을 설치하는 경우 입니다. 이 경우 cpan을 이용하는 경우나 직접 make를 사용하는 경우 모두 C/C++ 컴파일러를 이용해서 관련 라이브러리와 함께 컴파일을 시도합니다. 만약 여러분이 설치하려는 모듈과 관련한 개발 라이브러리가 시스템에 존재하지 않는다면 모듈의 빌드가 실패할 것입니다. 이 경우 해당 라이브러리의 개발 패키지를 설치하면 됩니다.
또는 빌드를 성공적으로 수행한 후 모듈의 테스트 과정이 이루어지는데 이 때 테스트에서 하나라도 실패한다면 모듈의 설치를 거부할 것입니다. 이 경우 테스트에 실패한 원인을 찾아서 해결을 해야지만 설치를 진행할 수 있습니다. 하지만 강제로 설치를 하려는 경우 cpan 프롬프트 안에서 다음과 같이 명령을 내리면 테스트에 실패하더라도 강제로 모듈을 설치합니다:
cpan[5]> force install Bundle::Gnome2
만약, make를 이용해 수동으로 설치하는 경우 강제로 설치하려면 다음과 같이 명령을 내립니다:
# make force install
성공적으로 모듈을 설치했다면, 프롬프트에서 다음과 같이 확인할 수 있습니다:
$ perl -MGtk2 -e 'print "$Gtk2::VERSION\n"'
1.142
$
위의 원-라인 커맨드(one-line command)의 -M은 사용할 모듈을 의미합니다. 즉 -MGtk2는 Gtk2 모듈을 사용하겠다는 의미이며, -e는 원-라인 커맨드로 펄을 사용하겠다는 의미로 뒤에 따라 나오는 ''안의 구문을 실행합니다. $Gtk2::VERSION 은 Gtk2 모듈안에 있는 $VERSION 변수를 의미합니다. CPAN 모듈은 모두 $ModuleName::VERSION 변수를 가지고 있습니다.
설치한 모듈을 사용하기 위해서는 use 키워드를 이용합니다:
use Gtk2;
다음은 Bundle::Gnome2 를 이용해 설치한 Gtk2 모듈을 이용하여 Hello World 메시지를 출력하는 간단한 예제입니다:
#!/usr/bin/perl -w
use strict;
use warnings;
use Gtk2 -init; # Gtk2 모듈을 사용하기 위해 필요한 부분
my $window = Gtk2::Window->new( 'toplevel' );
my $button = Gtk2::Button->new( 'Hello World' );
$button->signal_connect(
clicked => sub { Gtk2->main_quit }
);
$window->add( $button );
$window->show_all;
Gtk2->main;
여러분은 사용하고 있는 시스템의 루트 계정을 가지고 있지 않을 수도 있습니다. 이 경우 cpan 모듈을 사용해서 설치를 하거나 시스템 디렉토리에 빌드한 모듈들을 설치할 수 가 없습니다. 위에서 언급한 어려운 방법의 설치하기에 나온 것 처럼 압축을 해제한 다음 다음과 같이 빌드 및 설치 과정을 수행합니다:
$ perl Makefile.PL PREFIX=~/perl
$ make
$ make test
$ make install
이렇게 설치할 경우 자신의 홈 디렉토리 하부의 perl 디렉터리에 모듈이 설치됩니다. 하지만 여러분이 이렇게 설치한 모듈을 사용하려고하면, 모듈을 찾을 수 없다는 에러 메시지가 나타날 것입니다. 이것은 Perl 인터프리터가 여러분이 설치한 모듈들의 경로를 아직 인식하지 못하기 때문입니다.
명시적으로 라이브러리 경로를 설정하려면 소스 코드내에 다음과 같은 명령을 추가하면 됩니다:
#!/usr/bin/perl -w
BEGIN { unshift(@INC, '/home/yourhome_dirctory/perl/lib/site_perl/5.8.8'); }
하지만 위의 방법은 이해하기가 무척 어려운 코드처럼 보일 수 있습니다. 기능적으로 동일하지만 아래와 같은 깔끔한 방법을 사용하시기를 권장합니다:
#!/usr/bin/perl -w
use lib qw(/home/yourhome_dirctory/perl/lib/site_perl/5.8.8);
대부분의 경우 많은 사람들이 사용하는 모듈들은 번들(Bundle)로 존재합니다. 이런 경우 일일이 설치하기보다 cpan을 실행한 후 Bundle::* 패키지를 설치하는 것이 편리한 경우가 많습니다. 예를 들면 gtk2와 Gnome2 관련 패키지를 모두 설치하고 싶다면 Bundle::Gnome2 모듈을 설치하면 됩니다. libwww-perl 관련 모듈을 모두 설치하고 싶다면 Bundle::LWP 모듈을, 테스트 관련 모든 모듈을 설치하려면 Bundle::Test 모듈을 설치하면 됩니다. 또는 CPAN의 모든 모듈을 설치하고 싶다면 Bundle::Everything을 설치하면 됩니다.
cpan을 실행한 후 다음의 명령어를 이용하면 번들 모듈을 검색할 수 있습니다:
cpan[1]> b /Bundle::/
CPAN: Storable loaded ok
Going to read /home/keedi/.cpan/Metadata
Database was generated on Tue, 06 Feb 2007 03:14:14 GMT
Bundle Bundle::ABH (ABH/Bundle-ABH-1.05.tar.gz)
Bundle Bundle::ABH::Apache (ABH/Bundle-ABH-1.05.tar.gz)
Bundle Bundle::AMBS (AMBS/Bundle/Bundle-AMBS-0.02.tar.gz)
Bundle Bundle::Alphamail (AWKAY/Bundle-Alphamail-0.03.tar.gz)
Bundle Bundle::Apache (GOZER/mod_perl-1.29.tar.gz)
Bundle Bundle::Apache2 (PGOLLUCCI/mod_perl-2.0.3.tar.gz)
Bundle Bundle::Apache::ASP (CHAMAS/Apache-ASP-2.59.tar.gz)
...
Bundle Bundle::ebx (CLKAO/ebx-0.87.tar.gz)
Bundle Bundle::libnet (GBARR/Bundle-libnet-1.00.tar.gz)
Bundle Bundle::libservlet (IX/Bundle-libservlet-0.9.3.tar.gz)
Bundle Bundle::myxCal (OUBIWANN/Bundle-myxCal-0.03.tar.gz)
Bundle Bundle::perlWebSite (OUBIWANN/Bundle-perlWebSite-0.02.tar.gz)
199 items found
cpan[2]>
지금까지 펄의 CPAN과 모듈을 찾고, 설치하고 사용하는 방법을 알아보았습니다. CPAN에는 펄을 이용해 작업하는 개발자라면 누구라도 한 번쯤은 생각했을 법한 모듈은 거의 존재합니다. 만약 여러분이 어떤 기능을 구현해야 하는 상황이라면 펄 프로그래머로써 가장 먼저 해야 할 일은 CPAN에 접속해서 관련 모듈을 검색하는 일입니다. 제 경험으로는 적어도 펄 모듈이라면 구글보다 CPAN에서 찾을 확률이 높았습니다. CPAN을 이용해서 여러분의 작업을 더욱 쉽고 빠르게 해결하시기 바랍니다.
서비스 링크
아이디가 없으신 분은
회원가입 후 이용하실 수 있습니다.
/usr/lib/perl5/5.8.5/CPAN/Config.pm # CPAN 설정파일