Blog

Services in Italy -->

Writing an HTTP Server in Perl 6

Wed Jun 8 01:08:39 2011

spacer

Tags: Perl, Perl 6, Rakudo, HTTP, screencast

I took a long break from the screencasts but I think now I am going to be back making several new ones. I'll try to change the setup a bit and with the help of my son I plan to add some more video editing.

It is fun to prepare these short movies especially as it is now a family business but I also would like to know if you like what you see in these screencasts. So if you like them then please upvote them and tell your friends about them. Oh and don't forget to subscribe to my YouTube channel!

Now let's see the actual screencast.

Direct link to the HTTP Server in Perl 6 screencast

The latest source code release of Rakudo Star was more than a month ago but there was no binary version. As I recently learned how to create Windows installers for applications I built one for Rakudo as well and posted in my blog. ( Rakudo Star 2011.04 for Windows ). To get the file, go to the web site of Rakudo where you will find a link to the download page in Github. There you can pick the latest Windows Installer (currently rakudo-star-2011.04.v2.exe ) download it to your local disk and run the exe file.

For various reasons the installation path had to be hard coded and it is going to be c:\rakudo.

Once you installed Rakudo You can go to Start -> All programs -> Rakudo Star -> Rakudo REPL. This will open a small black window where you can start typing Perl 6 code:

  42.say

That's enough for now to be sure it works.

Rakudo Star also comes with HTTP::Server::Simple, a Perl 6 module to implement simple web servers. Just type in

  use HTTP::Server::Simple;
  HTTP::Server::Simple.new.run;

and you have a woring web server. Of course if you kill this web server you will also kill the Perl 6 REPL but we don't need it any more now.

We will take a look at the examples that are part of the HTTP::Server::Simple package. The first examples: 01-simple-base.pl6 is about the same as we typed in. It looks like this:

  use HTTP::Server::Simple;
  my HTTP::Server::Simple $server .= new; 
  $server.run;

The first line loads the module as usual. In the second line

  my HTTP::Server::Simple $server
  

declares a scalar variable called $server that must be of type HTTP::Server::Simple

The

   .= new;
   

part calls the constructor of the same class and assigns the result back to the left hand side. Finally

  $server.run;

calls the run method on the object launching the web server on its default port of 8080.

The second example ( 02-simple-small.pl6 ) is slightly more complex:

  use v6;
  use HTTP::Server::Simple;
  my $NL = "\x0D\x0A";
  
  class Example::Simple::Small is HTTP::Server::Simple {
    has %!header;
    has $!path;
    has $!query_string;
    method header ( $key, $value ) {
        %!header{$key} = $value;
    }
    method path ($path) {
        $!path = $path;
    }
    method query_string ($query_string) {
        $!query_string = $query_string;
    }
    # override the request handler of the base class
    method handle_request () {
        print "HTTP/1.0 200 OK";
        print "$NL$NL";
        say "<html>\n<body>";
        say "{self.WHAT} at {$!host}:{$!port}";
        say q{<table border="1">};
        for %!header.keys -> $key {
            my $value = %!header{$key};
            say "<tr><td>{$key}</td><td>{$value}</td></tr>";
        }
        say "</table>";
        say "Path: {$!path}<br/>";
        say "Query string: {$!query_string}<br/>";
        say "</body>\n</html>";
    }
  }
  my Example::Simple::Small $server .= new;
  $server.run; # now browse localhost:8080/whatever?name=value

It starts by making sure this code is only consumed by a perl 6 compiler, loads the module and then declares a new class called Example::Simple::Small subclassing the HTTP::Server::Simple.

  class Example::Simple::Small is HTTP::Server::Simple {

This is followed by the definition of 3 private attributes and then 3 methods to update those attributes. The main method (handle_request) will first print the name of the class, the host name and the portnumber. Then it will print an HTML table showing the details of the request header. Finally it also prints the path of the request and the query string. These are the essential parts of any HTTP request.

This is of course very bare bones but it allows you to start playing with this and start implementing web applications using Perl 6.

I am also sure that in any real application you will use a templating system and will not embed html in the Perl code.

End

Thank you for watching this video. If you liked it, please upvote it and comment on it to encourage me to make more such screencasts.

Oh, and don't forget to subscribe to the channel!


This entry was also sent out as part of the Perl 6 Tricks and Treats. Visit here to subscribe.

Watch more Perl 6 related screencasts.

see comments

Numerical URLs replaced by textual urls on my blog

Mon Jun 6 06:26:08 2011

spacer

Tags: Perl, blog, links

When I started to write this blog I used the timetamp of each post as the name of the page where the entry shows up. A couple of monthes ago a new feature was added that allowed the creation of the textual adresses. It is probably better for SEO but it makes it also easier for me to recognize in the logs which page are people visiting a lot.

Today I finished converting all my previous blog entries so they too will have such textual address. I setup redirections from the old pages to the new ones.

This means that if you linked to any of my pages those links should still work.

Nevertheless it would be nicer if all the links pointed to the new addresses. So if you have linked to one of my blog entries I'd appreciate if you could replace them with the new link.

I already went over the links on the about page of The Perl Editor and replaced them.

Which reminds me Ahmad Zawawi made some wonderful development that will soon show up in Padre fixing one of the most emberassing issues we had.

see comments

How to measure the success of Strawberry Jam?

Fri Jun 3 17:09:17 2011

spacer

Tags: Perl, Padre, IDE, Windows, install, distribution, Strawberry

I uploaded it, blogged about it, tweeted it, sent a few e-mails. Now what? How can I really measure its impact? How can I know if it is any good?

Quantitative measurement

Even the quantitative measurement is hard but let's try that for now.

I can look at the download counter.

For the previous package that was called "strawberry-plus-padre-0.63.msi" we had an average of 50 downloads/day through the past 11 months.

See the download count

The official Strawberry Perl had about 800 downloads/day since the latest release on 19 May. It came out in 3 flavors, the division is approximately 55 - 670 - 75 for 5.12.3.0-64bit - 5.12.3.0-32bit - 5.10.1.4-32bit respectively.

OTOH if I am not mistaken the historic average of Strawberry since February 2010 is about 390/day (~ 180,000/465 )

v3 of Padre on Strawberry was uploaded 4 days ago and there were 340 downloads since then. An average of 85 / day. It is certainly some increase compared to the historical numbers but it will flatten out. A month from now we will see clearer.

Unfortunately "download" does not mean "keeps using" but I think this is the best we can get today.

We might offer some server side service for this package that will encourage people to register. That might provide us with better numbers.

How else could I measure the success than a larger number of downloads? And what could be described as success?

Let's say I'd be happy to see an overall increase of "plain" Strawberry + Padre-on-Strawberry.

The name

Last time I suggested to call it Strawberry with cream but several people pointed out that there is a vim package which is called Cream. So that's not good.

Then someone on Reddit suggested Strawberry Jam. That sound like a good idea. Both as the food and as in Jam Session.

Strawberry Jam Session

Where all the CPAN modules play together.

Sounds ok but maybe I need something totally unrelated to Strawberries and Perl.

see comments

Rakudo Star 2011.04 for Windows

Wed Jun 1 11:08:25 2011

spacer

Tags: Rakudo, Perl, Perl6, Windows, install

I am really surprised by myself. In the last 10 years I mostly have various Linux distributions on my computers and I only used Windows at clients or in a virtual environment to make sure the perl editor works reasonably well there. Yet somehow I became the "Windows guy".

I am really surprised that somehow I am now creating installers for various things on Windows. First the Strawberry Perl with Cream - 5.12.3 v3 released and now Rakudo Star.

If you don't know, Rakudo is one of the most advanced compilers of Perl 6. Rakudo Star is a distribution that includes Rakudo, the compiler, Parrot, the virtual machine, a number of third party modules and documentation.

It is released in source code format and you can read more in the release announcement.

To make it easier to get started with it on Windows I built an installer for this package. It is a bit experimental for me as I am really new to building installers for Windows but Inno Setup makes it really easy.

Both the source code version and the Windows installer can be found on the download page of Rakudo.

There is one important limitation of Parrot I think, that the installation cannot be moved. So it will install the whole thing in the C:\rakudo directory.

If you would like to get some introduction to Perl 6, I made a series of screencasts about Perl 6.

Enjoy, and let me know how does it work out for you!

see comments

Strawberry Perl with Cream - 5.12.3 v3 released

Sun May 29 23:01:39 2011

spacer

Tags: Padre, Perl, IDE, Windows, release, Moose, Dancer

Strawberry Perl is great but for my recent Advanced Perl training class I needed a package that included the latest version of Padre, the Perl editor with the oversize ego and a number of other modules. Eg. Try::Tiny, Moose and Dancer.

So first I zipped all the files in the c:\Strawberry directory of my own Windows machine and posted about it: Padre 0.84 on Strawberry Perl 5.12.3 released. Then, based on the response of Curtis Jewell I further improved the package and now, with help from Mark Dootson, I managed to build a self installing package that already configures itself.

Yippee!!

We still have not moved it to the main download page of Padre but you can already find the download link on our wiki at the top.

The package contains a lot of modules. It contains DBD::mysql, DBD::Pg and DBD::SQLite that came with Strawberry Perl already and it also contains MongoDB.

All the dependencies of Task::Kensho were added (e.g. Log::Dispatch, Try::Tiny, Moose, POE, DBIx::Class and a lot more). It also includes Dancer with several plug-ins.

For Moose I added MooseX::StrictConstructor and MooseX::Singleton into the mix.

For the more office related people there are Spreadsheet::ParseExcel, Spreadsheet::WriteExcel, Excel::Writer::XLSX and Spreadsheet::WriteExcelXML.

Of course it also includes Wx as it is used by Padre and two main plug-ins for using Perl::Critic and Perl::Tidy.

The use of enhanced compression by Inno Setup also mean that the download size is not 44 Mb instead the 80 Mb I had in the previous edition even though I added a lot more CPAN modules. The installed size is almost 300 Mb.

How to call the kid?

As for naming I am unsure. I started to call it Padre-on-Strawberry when it was mostly about making it easy to distribute Padre but now that so many other things are already packaged, Padre is just one component. So I started to consider calling it some other name. E.g. Strawberry with Cream but I am not sure if that would not cause confusion. I certainly don't want to pose as a replacement of Strawberry. In the best case it is a derivative of the official Strawberry Perl release.

Anyway. If you have an MS Windows box, please give it a try and let me know what do you think.

see comments

Padre 0.84 on Strawberry Perl 5.12.3 released

Fri May 20 21:19:27 2011

spacer

Tags: Padre, Perl, IDE, Windows, release

Curtis Jewell has recently released Strawberry Perl 5.12.3.0 so I went ahead and built a package that also includes Padre 0.84, the latest source release on CPAN.

It is a zip file and there is no installer for it. You can download it from here.

Once downloaded, follow the instruction on that page.

Comments are welcome here or on the regular channels of Padre, the Perl IDE.

see comments

Digging CPAN

Sat May 14 16:51:40 2011

spacer

Tags: CPAN, search, analyze, CPAN::Digger, Perl

I have been silent for a long time due to too much work on one hand and a long vacation on the other. In between the two I squeezed in a little bit of coding to make my little project usable. At least I try to make it work for myself.

The web site is called CPAN::Digger. It is a site to collect and display some information about CPAN modules and other Perl code. It is at a very early and ugly version but some of you might find it useful.

The part that might be interesting for some people is that it is using PPI to collect data from the modules. It use the PPI based syntax highlighter that was originally written for Padre and it uses PPIx::EditorTools to generate a json file with the list of methods of each package. This is basically the outline view of Padre.

You can already see the results on the right hand side of this page

It also uses Perl::MinimumVersion to find out the minimum version of perl required by each module. These numbers are used to show what is the minimum version of perl each distribution requires.

Perl::Critic is also used on each module using level 4 criticism. It is very experimental. I think it will be interesting to see what issues are common to perl modules and maybe draw a conclusion regarding which policies are in consensus and which is not.

I hope some of these might be interesting to you too.

The source code is available on Github.

Comments, criticism, bug reports and patches are welcome!

see comments

Some stats from Google Summer of Code

Sat Apr 9 22:08:31 2011

spacer

Tags: Gsoc, Perl, statistics, 2011

The Google Summer of Code has a list of accepted organizations. Next to each organization there are a bunch of tags. One can download the all the data as a csv file.

So I looked at the data and grepped it for several keywords.

Here are the results sorted by number of hits.

 python     59
 ' c++'     40
 java,      37
 ' c,'      32
 javascript 32
 php,       24
 perl       17     <---
 linux      14
 sql        11
 ruby        9
 xml         9
 html,       9
 json        4

Counting the word java yields 60 results but that includes javascript as well so I added a comma after the word and counters java,

There are a lot of URLs in the listting that have php in them. counting pho gives 45 reuslts but apparently about 20 of those are urls. That might also mean something.

see comments

Keeping the code clean in a large Perl project

Tue Mar 1 02:06:41 2011

spacer

Tags: Perl, tidy, Padre

In the Padre we have been using Perl::Tidy to make sure the code looks the same around the whole project. It is not perfect but we felt that it is better to have a not perfect standard than to hope that everyone will write in the same nice way.

We have project wise Perl::Tidy configuration file and a script in our tools directory that will go over all the files and tidy them.

In order to make it easy to separate real code changes from purely layout changes we used to have perl tidy runs once in a while. This of course generated big changes at those times and "svn blame" is now less usable because of that.

So recently we started to discuss the possibility to change the strategy and to run perltidy on every commit.

The assumption is that if everyone does this then every tidy will only effect the code s/he just changed so it won't make it harder to see the actual change. On the other hand it will eliminate the big tidy changes.

We even discussed the possibility to run automatic perltidy on the code and check it in to the repository.

We don't yet have a final decision so I'd be interested to know how other people handle this?

I assume in project where there is only one developer this is a non-issue.

How do larger projects handle it?

see comments

Volunteer to an Open Source project with little or no programming background

Tue Mar 1 01:00:50 2011

spacer

Tags: Open Source, Padre, Perl, testing

On one hand there are many people out there who would like to contribute to open source projects but either don't have much time or feel that their knowledge is not enough.

On the other hand we would like to improve the quality of Padre, the Perl IDE. As it is a desktop project we find it very hard to write automated test.

I think this is an opportunity to let more people be involved in the development of Padre by offering them tasks they can do even if they have little or no programming background.

Zeno Gartner has started to write a number of use cases for Padre that builds up to become a check-list of items to be tested.

We need help in writing down similar use cases and to actually check Padre according to them before every release.

Each use case will be short, maybe 2-3 minute long so people can do one when they have a few minutes spare time. Later we will need to provide a way for people to report which use-cases have they checked, on which version of Padre, on what operating system and how did it go? Did the test pass or fail?

The pre-release checklist already has a few items on it but it needs a lot more items.

So we need people who would like to contribute but don't feel they have a lot of expertise in writing Perl and/or don't have a lot of time.

The only thing we ask is some kind of a commitment that you will help us on a regular base till you tell us otherwise.

If interested, please contact me directly or all the Padre developers:

Get on the IRC channel or mailing list of Padre and ask around.

see comments
spacer

Invite me for a Perl training

Blog entries
2011 Jun 08

Writing an HTTP Server in Perl 6
2011 Jun 06

Numerical URLs replaced by textual urls on my blog
2011 Jun 03

How to measure the success of Strawberry Jam?
2011 Jun 01

Rakudo Star 2011.04 for Windows
2011 May 29

Strawberry Perl with Cream - 5.12.3 v3 released
2011 May 20

Padre 0.84 on Strawberry Perl 5.12.3 released
2011 May 14

Digging CPAN
2011 Apr 09

Some stats from Google Summer of Code
2011 Mar 01

Keeping the code clean in a large Perl project
2011 Mar 01

Volunteer to an Open Source project with little or no programming background
2011 Feb 21

Can we rely on Perl?
2011 Feb 20

FOSDEM 2011 and Perl
2011 Feb 20

Tel Aviv Perl Mongers: Getting started in open source
2011 Feb 14

Accessing the official TPF wiki
2011 Feb 08

Grants to invite speakers to (non-Perl) events
2011 Feb 04

Linux Tag Berlin 2011, late call for talks
2011 Feb 02

Perl Ecosystem Group announcement and public discussion lists
2011 Jan 31

Perl at FOSDEM 2011
2011 Jan 20

The responsibility of a CPAN developer
2011 Jan 20

Texas Linux Fest - Call For Papers
More entries

Tags
Perl (311)
Perl 5 (94)
Padre (85)
IDE (44)
Perl 6 (44)
testing (40)
CPAN (31)
business (27)
newsletter (24)
marketing (23)
Windows (21)
open source (20)
training (20)
promotion (20)
ecosystem (19)
TPF (19)
Israel (18)
Parrot (17)
FOSDEM (17)
grants (16)

Follow them
Stormy Peters
Planets
Ironman Perl Planet
Perl Sphere
Planet Perl
Perl 6 planet
Perl Blogs
Perl Foundation News
gipoco.com is neither affiliated with the authors of this page nor responsible for its contents. This is a safe-cache copy of the original web site.