I recently held a introduction to the Mojolicious web framework for Oslo.pm. Here are the slides:
Posts Tagged ‘Perl’
Like most serious Perl people, CPAN is the main reason I still use Perl after all this time. This huge, wonderful library of Perl code usually helps me avoid reinventing any wheels. On the other hand, the standard CPAN client is one of my most regular hate objects when coding Perl.
It’s not that it lacks any features I need, rather the opposite, the damn thing has a million options, and no good defaults. CPANPLUS is only adding to this mess with even more options. However, now there’s a better solution.
Check out miyagawa’s new CPAN client cpanminus. And when I say check out, I mean it literally. Get it from github so you won’t have to bother configuring the default cpan shell again:
$ git clone git://github.com/miyagawa/cpanminus.git
You might want to use one of the tagged releases rather than master tho. Install it in the regular way (perl Makefile.PL && make install) and you’re good to go. Using it is a breeze:
Command-Central:cpanminus marcus$ cpanm Mojo
Fetching http://search.cpan.org/CPAN/authors/id/K/KR/KRAIH/Mojolicious-0.999921.tar.gz
Building and testing Mojolicious-0.999921 for Mojo…
Mojo installed successfully.
cpanminus gives you all the information you want and nothing more, and it asks no questions. If you want to see the full build output, you can check out ~/.cpanm/build.log
In addition to recent fatherhood and doing my own startup, I am now the leader of the Oslo Perl Mongers. Look forward to tech talks from Oslo.pm in the months to come. :)
If you want to write tests for your JavaScript code from Perl, Claes’ module Test::JavaScript::More comes in handy. This module works by evaling everything from the use line as JavaScript. Of course, now you’re mixing two languages in one file, which is not going to make any of your syntax validators happy. However, loading it like this will please both perl and jslint:
m| /* |; # Comment out JavaScript use Test::JavaScript::More; __END__ = ''; // It's is all JS from here. */ ok(1,'Success!');
One final note. I had some problems building the cpan module of JavaScript on OSX with Spidermonkey from ports. If you have the same problem, get the latest and greatest version from GitHub, which fixes this issue.
A really simple tutorial for creating these 2d-barcodes that you see android use all the time.
Hey there, the internet is a turbulent place, and since I’ve moved around quite
a few times, I think I forgot to introduce myself the last time I made the
move. I am Marcus Ramberg, the writer of this blog, and director of
Nordaaker, a small British/Norwegian company currently run out of Oslo,
Norway. In addition to being my personal blog, at the time being this blog
acts as Nordaaker’s dynamic english presence. As the other director of
Nordaaker, Arne Fismen runs our norwegian presence.
In one form or another, I’ve been writing on the internet since around
2002, when I set up my first own domain, thefeed.no.
Back then I was running my own Movabletype installation.
Thanks to the glorious Internet Archive you can see my
first blog the way it looked about a year after it’s launch. It is
very strange for me to go back and read the thoughts I had so many years
ago.
I was also hosting other blogs on my movabletype installation, including
slemmen, who wrote about sysadmin stuff and some college friends like
marlboro and gry.
On the front page we had a perl script that aggregated all the blogs,
a simple planet if you will.
Back then, I wrote a lot less about tech than I do now. Looking at the
categories, we see that the three biggest ones are Travel[44], Geek[36]
and Opinion[26]. Still, even then I was journaling things from the
Perl Community. However, checking back around 2005, a few years
later, Geek[108] was dominant, With Opinion[49] and Mac[34] as the next
ones. Perl is trailing 4. with 27 posts. I also wrote 18 book reviews
About that time I gave my first talk about a MVC framework.I was
already active in the community, contributing a Mason view to Maypole,
my third CPAN module. I had been using Mason at work for a couple of years
by then. It was not until I started working for ABC Startsiden that I started
using Template Toolkit.
About then, disaster struck. My server HDD died, losing a lot of images
from our image galleries. After that, I lost a lot of the motivation for
running thefeed, given the risks. Losing people’s personal data isn’t fun.
At least I am glad that the blogs are preserved in the internet archive.
It took a while for me to start writing again after that, but in the period 2006-2009
I decided to use hosted solutions, keeping both a vox blog and a
livejournal, before finally moving to this blog installation.
I’m self-hosted again, and the software might vary, but I hope the addresses
will last for a long time :)
09:52 < @rafl> wow.. you can actually see how old that code is 10:00 < @rafl> but it still runs without a single modification. nice! 10:00 < @rafl> catalyst++ 10:14 < @marcus> rafl: try that with rails :) 10:14 < @rafl> no, thanks
Code rot is everywhere, but some platforms suffer more than others. Even Simple C++ code suffers from code rot.
One major factor in Catalyst’s success has been extensibility. I plan to
do a series on extensions that I’ve found useful recently. To kick it off,
I’ll feature a model which gives me a simple and useful admin interface to
my DBIx::Class models.
When I first got involved with MVC Web Frameworks like Maypole and Ruby on
Rails, a big selling point was the ability to generate CRUD (Create/Read/
Update/Delete) interfaces to your data model. Ruby on Rails does this through
a mechanism called scaffolding, where it adds a set of actions to your
controller. It soon became apparent that these CRUD frameworks did not live
up to their promise as a base for creating your own custom actions. Usually,
you spend more time customizing these controllers than you would just
implementing the features you require.
However, there is still a good use for these for giving your admins a
direct interface to your data model. There has been several iterations of
these tools for the Catalyst framework, but with Catalyst::Plugin::AutoCRUD,
I’ve finally found something easy to plug into your existing app, which
integrates well with most setups.

For most apps, all you need to do is plug it into the main application class
by adding AutoCRUD to your list of plugins. This will plug a complete CRUD
application, including controllers and view and templates into your app.
By default it will attach itself at ‘/autocrud’, but you can easily change
that in config. Just add this to your config file:
basepath admin
and it will respond to /admin/* instead. Another common requirement is to
add authentication for the admin interface. One way to accomplish that is
by using Catalyst’s auto handler functionality. Add a method like this in
your Root controller
sub auto :Private {
my ( $self, $c ) = @_;
if ($c->action->reverse =~ /^autocrud\//) {
$c->authenticate({},'users');
}
return 1;
}
Note that my example is using HTTP Basic auth. The actual authenticate call
needs to be customized for your realm.
AutoCRUD supports multiple DBIC Schemas, and if will automatically provide you
with a list to let you pick which one to work with. After that, you choose
a Result class, and you have access to an extensive AJAX-enhanched database
admin tool. You can search and browse data, as well as edit it and add new
rows easily. AutoCRUD also understands your DBIC relationships, so you can
easily see data related to the current rows.
Like it’s predecessors, I do not recommend trying to make this tool
into a generic ‘allweb’-application. However, if you use it for what it is,
you can save countless of development hours making trivial admin tools. Since
it works again your DBIC Schema, you’ll also get the advantage of keeping
your business logic in the data model. Things like DBIC timestamps will
Just Work.
There still might be some polishing left to do on AutoCRUD, but I already
find it a hugely useful tool. You can install it just like you would any other CPAN module using
$ cpan Catalyst::Plugin::AutoCRUD
09:30 < @sri_> there is absolutely no way to detect the server base as far
as i can see
09:33 < @sri_> you really have to do horrible things with PATH_TRANSLATED...
09:34 < @sri_> seriously... was that thing developed by a bunch of monkeys?
10:00 < marcus> yeah, they were trying to write shakespeare's collected works,
and ended up with IIS instead
In a recent post Dave Rolsky points out some of his own best practices for Catalyst. While I’ve come around to agree with his first point, that Catalyst should generate a reusable config class for the user, I’m not so sure with regards to his model viewpoints.
For me, the strength of Catalyst’s Model layer has always been the immense glue layer that allows me to configure any model in a predictable way. Much like DBI gives me a unified way to talk to databases, the Catalyst model-layer gives us a unified way of configuring models. In addition, we are able to provide helpers to create these models from the command line, reducing the work needed to set up a new model.
I will grant Dave that the API for the model adapters could be better. It is my hope that we will accomplish as Catalyst takes advantage of more of the new stack that Moose provides. In particular I am excited about the work Devin Austin is doing for GSOC on improving the -Devel package. This is an area where we can significally improve without too much worry about backwards compability. For instance, the KiokuDB model already uses moose accessors for config.
Dave’s example only limits itself to talking to a SQL store via DBIx::Class. However, real world applications typically have several models. In some of my apps I talk to S3, or Queue servers, or LDAP stores for user management. This shows the true power of the Catalyst model layer.
I also hope that we can provide a different way to tie models to controllers. This should be part of the moosify branch of Catalyst-Runtime. I disagree that $schema->resultset(’Person’) is a significant improvement on $c->model(’DBIC::Person’). Controller code is not meant to run without a context anyways.
I hope that by looking at Moose Extensions, we will be able to find a more suitable API for this functionality. Of course, we have a lot of work ahead of us, but I am really starting to like what Catalyst has turned into.
