Re: BlindProgramming.com site

  • From: "Octavian Rasnita" <orasnita@xxxxxxxxx>
  • To: <programmingblind@xxxxxxxxxxxxx>
  • Date: Fri, 29 Feb 2008 19:46:39 +0200

As I told, Wikipedia doesn't tell what's the best.

They say that there are more than 1000 Drupal modules, and as you might have seen, they tell about some other web frameworks, but if you will search for "Catalyst" on search.cpan.org, you will see that there are more than 1000 results also. And this is irrelevant, because in a Catalyst, or Gantry, or CGI::Application::Framework or Maypole framework, you can use thousands of other perl modules that do the hard work, and you will also find modules that do things that the pre-made modules in other languages don't do.

Of course, the most important thing that need to be reminded when choosing a framework is the programming language it uses. (Well, of course that in perl you can use code in other languages, but I guess that who knows well other languages, they would prefer to create their programs in a framework made specially for their prefered language.)

If you need to choose a framework based on what language you know better, it won't be too hard to choose, because for each language there is a framework or two which is generally considered the best.

If you want to choose based on what you want to do, it depends on what you want to do. If you want to create a very simple site, like blindprogramming.com for example, you can use any language and any framework, and it should work wonderfully.

On the other hand, if you want to do more complicated things like presenting stock quotes, stock charts or other financial data, perl would be prefered, because it has very many helpful modules that can fetch data from many sites with a very nice and easy to use programming interface.

Of course, there are other domains like biotechnology for which perl has many modules, there are books written about these subjects, and so on.

But as far as I know, all the perl frameworks and CMS use to provide clean URLS like www.site.com/foo/bar, with no file extension at the end for letting you know that those sites are made using perl. However most of the php sites promote the php extension, and even the sites made in Python or Java.

I have started making web apps from the scratch in perl, without even using the CGI module, and I used to encode and decode the query strings and the content of web POSTs, and then I passed to create standard CGI scripts, then I've created my own templating system that was very limited, then I started to use the templating system HTML::Template.

I've learned step by step and this helped me to understand better the way a web app work, but it should have been much better if I would have started directly with higher level programs like a framework.

Now I am creating apps with Catalyst which is a MVC web framework, I guess that it is the most used perl framework. It has it's own web server that can be used for testing the app, and it runs well under Windows and Linux. I could use any templating system I want, but the default one is my prefered templating system (Template-Toolkit), and Catalyst has some helper programs that can help creating the base templates. That templating system can create html documents, but other file formats also, it can load perl modules inside and do many things inside the template.

Catalyst can use different ORMs, but the default (and the only one I know) is the most used (DBIx::Class) that has many improvements over other ORMS.

It can work with MySQL, PostgreSQL, MS SQL, Oracle, and if I remember well with Sybase and SQLite also.

Catalyst has a helper program that can create the DBIx::Class class files with a single command line. It connects to the database, parse the structure of all the tables inside, and create a class file for each table.

The main part of programming in a MVC application is done in controllers, which are perl modules. They have a very simple structure but they can be also created with a helper application of Catalyst.

As an example, a controller could look like this:

package MyApp::Controller::Library;
use base 'Catalyst::Controller';

sub book : Local {
my ($self, $c, $id) = @_;
my $book = $c->model("MyDB::Books")->find($id);
$c->stash->{book} = $book;
}

Of course this subroutine could have been written with only 2 lines instead of 3, but I wrote it this way for beeing easy to understand.

$c is the context object that can be used to access the databases, to get the parameters from forms, to print the data to the browser, to print to the log files, to forward to another URL, etc.

The user executes that subroutine when accessing an URL like:

http://www.site.com/library/book/23

Where "23" is taken in $id in this subroutine.
"Library" is the name of the controller, and with all lowercases "library" is the first part of the URL, and "book" is the second part of it.

But of course, this way (Local) of dispatching the URL to the actions (the subroutines) is not the only one. There are other more complex ones.

The line
my $book = $c->model("MyDB::Books")->find($id);

makes a "select * from books where id=23" and stores the result in an object so you could do later things like:

my $book_name = $book->name;
my $book_author = $book->author;

where the "name" and "author" are fields in the "books" table in the MyDB database.

But you can get those values in your templates directly.
The last line from the subroutine stores the object $book in the stash, and from there it can be accessed in templates. In a Template-Toolkit template, they can be accessed this way:

Book name: <b>[% book.name %]</b>
Book author: <i>[% book.author %]</i>

Of course, the object could contain an array of books with their values, and it can be used to create a table, or the options of a combo box, or a list, etc.

To delete the book from the table "books", the code should be:

$book->delete;

To update the book in the database table, the code is:

$book->update({
author => "The correct author",
year => 2006,
});

To insert a book in the table of books, the code should be:

$c->model("MyDB::books")->create({
name => "The name of the book",
author => "The author",
year => 2005,
});

Of course, DBIx::Class allows relations among more tables, allows primary keys with more fields, allows searching using complex relations.

The framework has many modules that can be used for authorization and authentication, and after configuring them in the main module of the application, you can check the permissions of the current user, with something like:

if ($c->user_exists) {
$c->body("access ok");
}

or

if ($c->check_any_user_role("admin", "operator")) {
...
}

Octavian

----- Original Message ----- From: "Jamal Mazrui" <empower@xxxxxxxxx>
To: <programmingblind@xxxxxxxxxxxxx>
Sent: Friday, February 29, 2008 6:02 PM
Subject: RE: BlindProgramming.com site


Thanks, Octavian and Pratik, for helping me understand the difference
between a web application framework and content management system.  below
I have pasted excerpts from the Wikipedia page referenced by Octavian that
indicate a blurring of the line between such technologies.  I take the
point, however, that they start with different philosophies and different
ends of a programming spectrum.

Besides Drupal, are there other content management systems that folks have
found highly usable, both from the perspective of a blind developer and
user?  I notice that Drupal uses PHP for customizations done by
programming.  So, I suppose one's language preferences are a factor as
well.

Regards,
Jamal

[From Wikipedia]

Some self-described content management systems have begun to expand into
higher layer web application frameworks. For instance,
Drupal
's structure provides a minimal core whose function is extended through
modules that provide functions generally associated with web application
frameworks.

Joomla
and
Plone
have similar functionality. Historically these projects have been termed
content management systems
. However, it is debatable whether "management of content" is the primary
value of such systems. Add-on modules now enable these systems to function
as
full fledged applications beyond the scope of content management. They may
provide functional APIs, functional frameworks, coding standards, and many
of
the functions traditionally associated with Web application frameworks.


... software projects like
MODx,
Drupal,
Joomla
or
Typo3
have begun to morph from web content management systems to a higher layer
web application framework. Their structure generally provides a minimal
core
whose function is extended through modules that provide functions
generally associated with web application frameworks. As
open source
projects, their communities contribute many modules (for example,
Drupal
has over 1,000 such modules and Typo3 more than 2,500). Use of these
CMS's core+modules constitutes a method for assembling a website with a
broad range
of application features without actually doing any PHP-level coding.
__________
View the list's information and change your settings at
//www.freelists.org/list/programmingblind


__________
View the list's information and change your settings at //www.freelists.org/list/programmingblind

Other related posts: