Perl Project Improvement(1) Perl Installation and CPAN

Perl Project Improvement(1) Perl Installation and CPAN
> perl -v
This is perl 5, version 16, subversion 0 (v5.16.0) built for darwin-2level

CPAN installation
Log::Log4perl
YAML::XS
Data::Dumper
DBI
IOC
Redis
Time::Piece
Path::Class
autodie
Thread::Queue
DBD::mysql
threads

If CPAN install is not working, you may need force install.

1 Install DBI on MAC
>cpan App::cpanminus
> cpanm DBI
> perl -MCPAN -e 'shell'
cpan> get DBD::mysql

>cd  /usr/local/lib
> sudo ln -s /usr/local/mysql/lib/*.dylib .
> cd ~/.cpan/build/DBD*/
> sudo perl Makefile.PL --testuser='test'
sudo make and sudo make install
> sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/local/lib/libmysqlclient.18.dylib
> export DLYD_LIBRARY_PATH=/usr/local/mysql/lib

Show the Perl Directory:
> perl -e 'print join ("\n", @INC) . "\n";'
/home/ec2-user/perl5/lib/perl5/x86_64-linux-thread-multi
/home/ec2-user/perl5/lib/perl5
/usr/local/lib64/perl5
/usr/local/share/perl5
/usr/lib64/perl5/vendor_perl
/usr/share/perl5/vendor_perl
/usr/lib64/perl5
/usr/share/perl5
.

Run the Perl test cases
> prove t/*

2 Manually Install Perl
http://perldoc.perl.org/perlmacosx.html
http://www.cpan.org/src/
> curl -O http://www.cpan.org/src/perl-5.22.0.tar.gz
> ./Configure -des -Dprefix=/Users/carl/tool/perl-5.22.0
Make and Make Install

Build with supporting for threads
> ./Configure -des -Dusethreads -Dprefix=/Users/carl/tool/perl-5.22.0

threads and forks
http://stackoverflow.com/questions/22036985/error-using-thread-module-this-perl-not-built-to-support-threads

I checked the version on all the servers, I am using this old version.
> perl -v
This is perl 5, version 16, subversion 3 (v5.16.3) built for x86_64-linux-thread-multi
(with 25 registered patches, see perl -V for more detail)

So I will manually install the version on CentOS Docker Image

3 Manually Install Perl on CentOS Docker Image
> wget http://www.cpan.org/src/5.0/perl-5.16.3.tar.gz
> ./Configure -des -Dprefix=/tool/perl-5.16.3

Error Message:
I can't find make or gmake, and my life depends on it.
Go find a public domain implementation or fix your PATH setting!

Solution:
yum install -y gcc
yum install -y make

https://github.com/luohuazju/sillycat-docker/blob/master/centos7-nginx/Dockerfile

> make
> make install

If we install that on docker image, we can ignore the -Dprefix, because we do not want to set up PATH.

This can by pass the CPAN command confirmation.
export PERL_MM_USE_DEFAULT=1

cpan -fi Log::Log4perl YAML::XS

cpan -fi Log::Log4perl YAML::XS Data::Dumper DBI IOC Redis Time::Piece Path::Class autodie Thread::Queue DBD::mysql threads

cpan DBIx::Connector

or

cpan DBIx::Connector Log::Log4perl

cpan -fi autodie Thread::Queue threads

Install cpanm
> curl -L https://cpanmin.us | perl - App::cpanminus

Or
cpan App::cpanminus

Even this does not work
> cpanm --notest DBD::mysql

Error Message:
Can't exec "mysql_config": No such file or directory at Makefile.PL line 73.

Cannot find the file 'mysql_config'! Your execution PATH doesn't seem
not contain the path to mysql_config. Resorting to guessed values!

Solution:
yum install mysql-devel

The docker file configurations are as follow
Dockerfile
#Prepre the OS
FROM            centos:7
MAINTAINER      Carl Luo <[email protected]>

ENV             DEBIAN_FRONTEND noninteractive
ENV             PERL_MM_USE_DEFAULT 1

RUN             yum install -y gcc make wget
RUN             yum install -y mysql-devel
RUN             mkdir /install/
WORKDIR         /install/
#install perl
RUN             wget http://www.cpan.org/src/5.0/perl-5.16.3.tar.gz
RUN             tar zxvf perl-5.16.3.tar.gz
WORKDIR         /install/perl-5.16.3
RUN             ./Configure -des -Dusethreads
RUN             make && make install
RUN             cpan -fi Log::Log4perl YAML::XS Data::Dumper DBI IOC Redis Time::Piece Path::Class
RUN             cpan -fi autodie Thread::Queue threads
RUN             cpan -fi DBIx::Connector
RUN             cpan DBD::mysql

#Install the Application
RUN             mkdir /share/
WORKDIR         /share/
ADD             dist/jobs-producer-1.0.tgz /share/
RUN             mkdir -p /mnt/ad_feed
RUN             mkdir -p /mnt5/ad_feed

#Start the Application
RUN     mkdir -p /app/
ADD     start.sh /app/
WORKDIR /app
CMD    [ "./start.sh" ]

Makefile
IMAGE=sillycat/jobs-producer
TAG=1.0
NAME=jobs-producer
REPOSITORY=registry.sillycat.com

push-local:
    docker push  $(REPOSITORY)/$(IMAGE):$(TAG)

app-clean:
    rm -fr dist
    rm -fr $(NAME)-$(TAG)

app-init:
    curl -sS https://getcomposer.org/installer | php
    php composer.phar install

app-build:
    mkdir -p ./$(NAME)-$(TAG)/logs
    mkdir -p ./dist
    cp -r ./conf ./$(NAME)-$(TAG)/
    cp -r ./lib  ./$(NAME)-$(TAG)/
    cp -r ./src  ./$(NAME)-$(TAG)/
    cp -r ./vendor ./$(NAME)-$(TAG)/
    cp *.pl           ./$(NAME)-$(TAG)/
    tar -cvzf ./dist/$(NAME)-$(TAG).tgz ./$(NAME)-$(TAG)

docker-context:

build: docker-context
    sudo docker build -t $(REPOSITORY)/$(IMAGE):$(TAG) .

run-stage:
    sudo docker run -v /opt/jobs-producer/logs:/share/$(NAME)-$(TAG)/logs -v /mnt/ad_feed:/mnt/ad_feed -v /mnt5/ad_feed:/mnt5/ad_feed -d -e RUNNING_ENV=stage --name $(NAME) $(REPOSITORY)/$(IMAGE):$(TAG)

debug:
    sudo docker run -v /opt/jobs-producer/logs:/share/$(NAME)-$(TAG)/logs -v /mnt/ad_feed:/mnt/ad_feed -v /mnt5/ad_feed:/mnt5/ad_feed -ti -e RUNNING_ENV=stage --name $(NAME) $(REPOSITORY)/$(IMAGE):$(TAG) /bin/bash

clean:
    sudo docker stop ${NAME}
    sudo docker rm ${NAME}

logs:
    sudo docker logs ${NAME}

publish:
    sudo docker push ${IMAGE}

start.sh
#!/bin/sh -ex

cd /share/jobs-producer-1.0
perl JobProducerApp.pl

References:
log4perl
http://unmi.cc/perl-log4perl-user-guide/

IOC
http://collaboration.cmc.ec.gc.ca/science/rpn/biblio/ddj/Website/articles/TPJ/2005/0501/0501a/0501a.html
http://perlalchemy.blogspot.com/2011/01/dependency-injection-or-removing.html
http://www.drdobbs.com/web-development/inversion-of-control-in-perl/184416179#l1
http://search.cpan.org/~stevan/IOC-0.29/lib/IOC.pm

Configuration File
http://perltricks.com/article/29/2013/9/17/How-to-Load-YAML-Config-Files

Mysql Connection
http://search.cpan.org/~capttofu/DBD-mysql-4.033/lib/DBD/mysql.pm

upgrade version and re-install
http://sillycat.iteye.com/blog/2193773

install DBI on mac
http://stackoverflow.com/questions/19565553/problems-with-perl-dbi-dbd-on-osx-10-9-mavericks

tap::harness test suite
http://www.4byte.cn/question/1518155/tap-harness-perl-tests-tee-output.html

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326851490&siteId=291194637