Showing posts with label install. Show all posts
Showing posts with label install. Show all posts

Thursday, December 26, 2013

Nitrous.IO: Dancing on the clouds


In a previous post about Preparing the dance floor I explain how to setup Dancer in several OS such as CygWin on Windows, Linux (Ubuntu and CentOS) and Mac OS X (OS X Mavericks) but recently I found that is possible to install and use Dancer on Nitrous.io.

Why Nitrous.io?

Why not? Nitrous.io is a cloud development environment this means you can code for free using a Web Browser in your computer or tablet; or even using a SSH client from anywhere. You also have access to a Web IDE and collaborative coding.

Nitrous.io allows to code in several programming language such as Ruby on Rails, Python with Django, Node.js and Go but it does not explain how to code with Perl on Dancer.

Installing Dancer on Nitrous.io.

The installation process is similar to what was explained in the post Preparing the dance floor but there is a few minor changes.

Cpanminus cannot be installed in a share directory you so cannot use the sudo option and the installation will be done in ~/perl5. After it is installed, the directory ~/perl5/bin need to be included in the PATH variable.
Now you are ready to update the Perl modules but this will increase the used storage. If you have some nitro (N2O) available it is recommended to get more storage.
Now you are ready to install dancer.

Create the application

To create the application and start it just do the same you do in other environment.
cd workspace
dancer -a myapplication
cd myapplication
mv bin/app.pl bin/server.pl
./bin/server.pl
To view the application, in the upper left side, select Preview > Port 3000. In the new browser tab there is your new application.

To have the application on Github follow the instructions from Nitrous.io help in http://help.nitrous.io/github-add-key/.

Nitrous.io is just another good option to develop your dancer application. There are pros and cons about this, but this is a great opportunity to dance in the clouds.

Friday, December 13, 2013

Preparing the dance floor

I think the Dancer tutorial is very good explaining how to install Dancer and start your first application. However there are a few things that are not there - and should not be there either - but may be important to have in every Dancer project. Let's start up an application from scratch.

I have tested this in Linux (CentOS and Ubuntu), Mac OS (OS X Mavericks) and Cygwin on Windows but I have not tested it in Windows directly. If you have, please, share your comments about it.

Install cpanminus and update your Perl modules.

cpanminus (cpanm) is much user friendly than cpan, I really recommend to install it and also other cpanm helpers such as cpan-outdated and cpan-listchanges.

In Mac OS X you have to add to the PATH variable the directory where cpanm was installed. In my Mac OS X 10.9.1 was installed in /opt/local/libexec/perl5.12/sitebin but confirm the path before do this.

Now you have them installed it's time to update your Perl modules:

Install Dancer

With cpanm the Dancer installation is very easy:

You can use the same command to update Dancer, in case you already have it installed.

Create your application scaffold

First thing you need to have is a working or hosting directory. If this is your development environment, you can use the directory Documents/workspace inside your home directory (Windows, Linux or Mac OS). If this is a Testing or Production environment, you can use /opt/ to host your application.

Now it is time to create the application with the command 'dancer -a application_name'. Notice that I used application_name, but you can use a module name like Dancer::application_name.

Once the application scaffold is created go to the application directory and execute it.

$ cd /home/$USER/Documents/workspace
# Or go to /opt if this is not a Development environment
# cd /opt
$ dancer -a myapplication
+ myapplication
+ myapplication/bin
+ myapplication/bin/app.pl
+ myapplication/config.yml
+ myapplication/environments
+ myapplication/environments/development.yml
+ myapplication/environments/production.yml
+ myapplication/views
+ myapplication/views/index.tt
+ myapplication/views/layouts
+ myapplication/views/layouts/main.tt
+ myapplication/MANIFEST.SKIP
+ myapplication/lib
  myapplication/lib/
+ myapplication/lib/myapplication.pm
+ myapplication/public
+ myapplication/public/css
+ myapplication/public/css/style.css
+ myapplication/public/css/error.css
+ myapplication/public/images
+ myapplication/public/500.html
+ myapplication/public/404.html
+ myapplication/public/dispatch.fcgi
+ myapplication/public/dispatch.cgi
+ myapplication/public/javascripts
+ myapplication/public/javascripts/jquery.js
+ myapplication/t
+ myapplication/t/002_index_route.t
+ myapplication/t/001_base.t
+ myapplication/Makefile.PL
 
$ cd myapplication/
$ ./bin/app.pl

Open a web browser and go to: http://localhost:3000 to see the new application with a page very similar to a new Ruby on Rails application.

I like to rename the bin/app.pl file to bin/server.pl.
mv bin/app.pl bin/server.pl

Here is where most of the tutorials finish with the installation or setup but what about git?

Git setup

This is an important step. Even if you are the only developer of the project, you always must have a version control and repository for the application. You can setup a git server in other server but I recommend to use GitHub if you can or your company permit it.

Create an account in http://github.com and create a new repository. Choose the same name of your application, enter a description, check on 'Initialize this repository with a README' and select .... What???, there is Perl, Ruby and Rails but no Dancer!!!!, well ....  select Perl in the 'Add .gitignore'. Click on 'Create Repository' and that's it.



In the next page there is a box at the right bottom corner with the title 'SSH clone URL'. Click on the 'copy to clipboard' icon or just copy that line. It will be something like this: git@github.com:your_github_user/myapplication.git.

Assuming that you already have git installed - if not, go to http://git-scm.com/downloads or google how to install git in your OS - go to the application directory to setup git. Execute these commands:
If you get an error about the public key (if this is your first time you will), then generate and add your key to github as explained here: https://help.github.com/articles/generating-ssh-keys

Now every time you made a change to the application you have to add the new files (if any), commit the changes and push them to github. Like this:

If you are working with a team or doing changes in different machines, you have to pull the latest changes from github before start working.
Or, if you want the code in a new machine or you want a new fresh copy just clone the application with:

To know more about git there are a lot of excellent documentation. For example:


Does Dancer have a Gemfile like Rails?

Unfortunately no, there is no such file in Dancer. However, you can make your own file, I name it Modfile and it have one module per line using the cpanm format:
#!/bin/bash

cpanm Module::Name[version]
cpanm git_repository
cpanm module.tar
Read the cpanm manual (man cpanm) to know more about this format. This is an example:
#!/bin/bash

cpanm Dancer
cpanm Dancer::Plugin::Database
cpanm Dancer::Plugin::FlashMessage
cpanm Template
cpanm Test::More                      # install Test::More
cpanm Net::SCP~1.0000                 # 1.0000 or later
cpanm Net::FTP~">= 1.0000, < 2.0000"  # latest of 1.xxxx
cpanm Net::SSH2@0.9990                # specific version. same as Net::SSH2~"== 0.9990"
cpanm git://github.com/plack/Plack.git
Save the file and give it execution permission with:
chmod +x Modfile
All the Perl modules required by the application will be updated, downgraded or installed to the latest or specified version executing the Modfile file:
./Modfile
You are almost ready to start coding, let's learn some steps first and you'll be ready to dance.