#cpanm
Explore tagged Tumblr posts
Text
New logicLAB Policies for Perl::Critic Released to CPAN
New logicLAB Policies for Perl::Critic Released to CPAN
Today I have uploaded a new release of my Perl::Critic::logicLAB, it lists the two new policies I mentioned on earlier occasions in my blog.
– Perl::Critic::Policy::logicLAB::RequireParamsValidate – Perl::Critic::Policy::logicLAB::RequirePackageNamePattern
Both released are released and maintained as separate distributions and Perl::Critic::logicLAB acts as a collection (Task::).…
View On WordPress
#challenge#community#contribution#cpan#cpanm#crap#distribution#github#neilb#perl#Perl::Critic::logicLAB#Perl::Critic::Policy::logicLAB::RequirePackageNamePattern#Perl::Critic::Policy::logicLAB::RequireParamsValidate#questhub#release#SourceForge
0 notes
Text
Compiling OpenSSL on Mac OS
A good number of years ago Apple deprecated OpenSSL in favor of SecureTransport. However, a lot of the modules in various programming languages still use OpenSSL, including Perl. And an increasing number of sites (like Stripe) require TLS 1.2, which is not supported on the old version of OpenSSL that ships with Mac OS. That means we either can’t connect to those sites from Mac using our favorite programming languages, or we have to find a work around. In my case, it is simply to compile my own version of OpenSSL to a custom location.
./Configure --prefix=/data/apps --openssldir=/data/apps/openssl --shared darwin64-x86_64-cc enable-ec_nistp_64_gcc_128 make depend make make install
It took me quite a while to figure out exactly how to do it in a way that would work. So hopefully that helps some of you out there trying to do the same thing.
If you’re using Perl, like me, then you might have to compile some modules that link against OpenSSL. Here’s how I did that:
cpanm Net::SSLeay --configure-args "INC=-I/data/apps/include LDDLFLAGS=\"-bundle -undefined dynamic_lookup -fstack-protector-strong -L/data/apps/lib\" LD=\"env MACOSX_DEPLOYMENT_TARGET=10.12 cc\" LDFLAGS=\"-fstack-protector-strong -L/data/apps/lib\"" --interactive --verbose cpanm --reinstall --verbose IO::Socket::SSL cpanm --reinstall --verbose LWP::Protocol::https
0 notes
Text
Let’s make browser testing fun again
Introduction
Tonight at the monthly Oslo.pm meetup, I gave a talk about how to test your web application in a real browser. This blog entry is a collection of the steps I went through while running live demos showcasing my module Test::Mojo::Role::Selenium.
My module uses Selenium::Remote::Driver which is a library that communicates with desktop browsers, such as Google Chrome, Firefox or even Internet Explorer. It comes bundled with test modules, but I wanted an interface that looks and feels like Mojolicious's test module Test::Mojo, since that module really makes testing fun.
Even if the module is a Test::Mojo role, it is not restricted to the Mojolicious web framework. The module can test any web site, as long as you have a web server running.
Why do you want to use this module?
Testing the HTTP messages for headers and body is great, but as soon as you make something other than an API or very simple web page, you should also test the user experience of the web app. Testing the JavaScript for dynamic web pages is the first that comes to mind, but responsive web pages also need testing, to see how elements are laid out on different screen sizes.
Test::Mojo::Role::Selenium allows you to write and run user experience tests in the browser of your selection. The syntax is very simple and it has sane defaults to avoid boilerplate in each test.
Prerequisites
To get started, you need to install the module and some executables that act as a glue between your test script and the browser of your selection.
# Install the test module $ cpanm Test::Mojo::Role::Selenium # Install Google Chrome, Firefox and PhantomJS drivers $ brew install chromedriver $ brew install geckodriver $ brew install phantomjs # Install the Selenium driver (requires jdk8) # brew install selenium-server-standalone
There are probably similar packages for your favorite operating system. The brew commands above are simply a cheat sheet for the presentation.
While preparing this article I wanted to get the demos running with Firefox, but I was not able to get the Selenium::Firefox module to work together with the geckodriver executable. Seems like the integration between firefox and geckodriver are under heavy development. Please let me know if I'm wrong. I did however manage to get Firefox running using the selenium-server. (I had to install Java though...)
You can change between the different backends using the MOJO_SELENIUM_DRIVER. environment variable. Note that Selenium::Chrome and Selenium::Firefox will start and stop the browser together with the test script, while Selenium::Remote::Driver (which uses selenium-server) require an external Selenium service to run.
Testing against a live web server
The first demo was to show that you can use the module to test any web site. The test mojolicious.t connects to mojolicious.org, checks for certain elements and fills in the search form, runs some JavaScript commands and then checks if the search result page was loaded.
Here are the commands I went through to run the demo:
$ mkdir -p test-selenium/t $ cd test-selenium $ vim t/mojolicious.t # copy/paste from t/mojolicious.t below # Test with Google chrome $ TEST_SELENIUM=http://mojolicious.org prove -vl t/mojolicious.t # Test with Firefox $ MOJO_SELENIUM_DRIVER=Selenium::Firefox \ TEST_SELENIUM=http://mojolicious.org \ prove -vl t/mojolicious.t # or... $ MOJO_SELENIUM_DRIVER=Selenium::Remote::Driver \ TEST_SELENIUM=http://mojolicious.org \ prove -vl t/mojolicious.t
The commands above should run the test script in various browser and result in a successful test run. Note that the environment variable TEST_SELENIUM need to be set, or the tests will be skipped. The reason for this is that I think in most cases the Selenium tests should not be run when installing a cpan module, nor being run on services such as Travis CI.
Testing against a local Mojolicious application
The next demo, internal.t, run tests agains a Mojolicious application. Using a Mojo app gives you some more features: In addition to test what is shown inside the browser, you can test headers and other "hidden" information that is exchanged over the HTTP protocol.
$ vim t/internal.t # copy/paste from t/internal.t below # Test with PhantomJS $ TEST_SELENIUM=1 prove -vl t/internal.t
Since the test script does not set MOJO_SELENIUM_DRIVER, it will use the default browser which is the headless browser PhantomJS. This browser is quite fast to start up, but might miss some features that is only available in Chrome, Firefox or Internet Explorer.
The headless version also takes screenshots which are saved to the operating system's temp directory. This can be changed by specifying screenshot_directory.
A more complex real life example
The last demo was to look at some tests for the Convos chat web application. The web app is a Mojolicious server that allows you to be persistently conected to IRC servers and communicate with other IRC users through your web browser. The frontend is powered by Vuejs, which is a reactive JavaScript library that can only be tested through the web browser.
The test suite feature many browser tests, (Look for the tests starting with selenium-) but the two tests that was demoed was selenium-url.t and selenium-register.t.
selenium-url.t
selenium-url.t simply tests the URL library url.js which is a URL parser and generator.
It does that by calling $t->driver->execute_script(...) which is a Selenium::Remote::Driver method for running JavaScript code inside the browser. The result from the method is then tested with normal Test::More functions.
selenium-register.t
selenium-register.t is a bit more complicated test that uses more features from Test::Mojo::Role::Selenium.
It uses wait_for to wait for elements that are injected dynamically to the document. wait_for() is a simple version of the more complex wait_until method that runs a function until the function returns a true value or a timeout runs out.
The end
I hope this introduction gave you an idea of what Test::Mojo::Role::Selenium can do, and makes testing fun again.
Resources
Links
Test::Mojo::Role::Selenium: API documentation.
Selenium::Remote::Driver: Holds information about what you can do with the driver.
Selenium::Remote::WebElement: Holds information about what you can do with an element.
Selenium::Remote::WDKeys: Check the source code for actual keys you can send to html elements.
t/mojolicious.t
use Mojo::Base -strict; use Test::Mojo::WithRoles "Selenium"; use Test::More; $ENV{MOJO_SELENIUM_DRIVER} ||= 'Selenium::Chrome'; my $t = Test::Mojo::WithRoles->new->setup_or_skip_all; $t->set_window_size([1024, 768]); $t->navigate_ok('/perldoc'); $t->current_url_is("http://mojolicious.org/perldoc"); $t->live_text_is('a[href="#GUIDES"]' => 'GUIDES'); $t->driver->execute_script( qq[document.querySelector("form")] .qq[.removeAttribute("target")]); $t->element_is_displayed("input[name=q]") ->send_keys_ok("input[name=q]", ["render", \"return"]); $t->wait_until(sub { $_->get_current_url =~ qr{q=render} }); $t->live_value_is("input[name=search]", "render"); done_testing;
t/internal.t
use Mojo::Base -strict; use Test::Mojo::WithRoles "Selenium"; use Test::More; use Mojolicious::Lite; get "/home" => "index"; my $t = Test::Mojo::WithRoles->new->setup_or_skip_all; $t->navigate_ok("/home") ->status_is(200) ->capture_screenshot ->header_is("Server" => "Mojolicious (Perl)") ->text_is("p" => "Hello!") ->live_text_is("p" => "Hello!") ->element_is_displayed("input") ->active_element_is("input[name=test]") ->send_keys_ok("input[name=test]", ["Yikes", \"enter"]); $t->current_url_like(qr{/home\?test=Yikes}) ->status_is(200) ->capture_screenshot ->live_element_exists("input[name=test][value=Yikes]"); done_testing; __DATA__ @@ index.html.ep <!DOCTYPE html> Test <p>Hello!</p> %= form_for "index", begin %= text_field 'test', autofocus => 1 %= submit_button % end
1 note
·
View note
Text
Plaggerをcpanminusとlocal::libで
cpanminusでCPANモジュールを手軽にインストール
App::cpanminus
cd ~/bin curl -LO http://xrl.us/cpanm chmod +x cpanm # edit shebang if you don't have /usr/bin/env
local::libをインストールするとユーザ領域にCPANモジュールをインストールできる
root権限いらず
local::lib
cpanm でlocal::libをインストール
cpanm -l ~/foo local::lib
local::libの設定(.bashrcに追記)
eval $(perl -I$HOME/foo/lib/perl5 -Mlocal::lib=$HOME/foo)
以上で、cpanminusとlocal::libのインストールが完了
Plaggerは、ウェブの情報をがしゃがしゃぽんするツール
Plagger
cpanmでPlaggerインストール
cpanm Plagger
たぶん失敗するので、~/.cpanm/build.logを確認
XML::Feed::RSSがインストールできなかったというようなログがでていれば、
強制インストールでとりあえず入る
cpanm --force XML::Feed::RSS
成功したら、もう一度Plaggerをインストール
今度は入るはず
21 notes
·
View notes
Quote
cpanm を使いユーザ権限でlocalにモジュールをインストール ここでは デフォルトのモジュールのインストール先を指定 ~/extlib perlにライブラリの検索pathを指定 ~/extlib/lib/perl5等 追加したらログインし直すか $ source .bash_profile します bash な方は .bash_profile 等に以下を追加export PERL_CPANM_OPT="--local-lib=~/extlib" export PERL5LIB="$HOME/extlib/lib/perl5:$HOME/extlib/lib/perl5/i386-freebsd-64int:$PERL5LIB" 以降このユーザ権限でcpanm MODULE すると ~/extlib 以下に全てのモジュールがinstallされます これ以外のディレクトリに入れたい場合は$ cpanm -l /path/to/dirname MODULE -lオプションで場所を指定する事で /path/to/dirname 以下に install できます
perlモジュールのinstallにcpanmを使う|perl|@OMAKASE
18 notes
·
View notes
Text
Perl : StrawberryPerl 에서 PAR::Packer 설치하기
보통은 아래와 같이 CPAN 을 이용해서 모듈을 설치할 수 있다. C:\> cpanm PAR::Packer 그런데, 최신 버전인 1.013은 에러 발생하며 설치 안된다. 부엉이님 께서 [Perl / Win32 / PAR::Packer - PAR::Packer 1.013 설치 중 windres: can't open file pp.manifest 오류가 발생하는 경우](http://www.nightowl.pe.kr/oblog/article/422) 에서 1.013 설치법을 설명을 해주었지만, 뭔가 좀 깔끔치 못한 느낌이다. 그래서, 바로 밑에 버전 1.012 을 설치하려고 하는데, 어떻게 해야될지 모르겠더라. CPAN 사이트에서 직접 다운로드 하여, 컴파일해서 설치할 수도 있겠지만, 좀 원시적인 느낌이다. cpan 을 사용해서 좀 더 편하게 설치할 수는 없을까? 하고 찾아보니, 방법이 없지는 않더라. PAR::Packer 1.012 의 실제 다운로드 주소가 http://search.cpan.org/CPAN/authors/id/R/RS/RSCHUPP/PAR-Packer-1.012.tar.gz 이며, 아래와 같이 설치한다. C:\> cpanm RSCHUPP/PAR-Packer-1.012.tar.gz 의외로 간단한 방법이었다. 여전히 뭔가 좀 불편하지만 말이다.
4 notes
·
View notes
Text
Cpanm Install
Cpanm Install
curl -L https://cpanmin.us | perl - --sudo App::cpanminus
peth 설정이 다 되어 있어도 local::lib error 발생할 때 이렇게 설치 해 준다.
eval $(perl -Mlocal::lib=~/??)
설정 되어 있으면 별 탈 없이 설치 된다.
0 notes
Text
Ansible playbook to install system wide Perl and its module using cpanm with cpanfile
On the other day, I posted How to install system wide perl5.18 on CentOS6.5 and I wrote an Ansible playbook to do this.
Here is the codes:
main.yml which has 2 shell scripts
Install System Perl on /opt/perl5 with plenv
Install Perl modules using cpanm with cpanfile
cpanfile
0 notes
Text
今って perlbrew で cpanm 入れるコマンドあるんだ?
perlbrew install-cpanm
知らんかった。もしかして最初から?
0 notes
Quote
cpanmin.usのインストールで”Can't locate ExtUtils/Manifest.pm”と言われたときは、”perl-ExtUtils-Manifest”をインストールしてあげましょう。
Boiler Room: cpanmin.usのインストールで”Can't locate ExtUtils/Manifest.pm”と言われたとき
0 notes