Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

perl as a php alternative

by iaw4 (Monk)
on Dec 05, 2015 at 03:49 UTC ( #1149446=perlquestion: print w/replies, xml ) Need Help??
iaw4 has asked for the wisdom of the Perl Monks concerning the following question:

Over the last 4 weeks, I have finally decided to learn php and mysql and written a 2000-line web system with it. About 50 files, 40 lines each. php has a few aspects that seem great: (1) it comes already installed--zero effort on ubuntu; (2) embedding code in HTML is easy; (3) the $_SESSION management is great, and I like the "global" keyword; (4) php has a wealth of built-in functions and google is good about finding the right docs, with mysqli being particularly convenient; (5) php has one standard, not different ones.

BUT php as a language is an inconsistent and complete mess. worse, what it was good for (which is quick-and-dirty embedded web pages) has been transmutated beyond recognition into a wannabe object-oriented system. it's also real strange. for example, classes allow declaration of variables, but this is not possible outside. huh? oh, functions just got it too in php7, but the global namespace still does not. what gives?? I wish php7 had focused on cleaning up the basics, such as variable declarations and a decent type system.

of course, complexity has also happened to a lot of other web frameworks. the web is easy for users and hard for programmers. yes, I understand that for large projects, MVC and injections are a good thing. but there are many small web projects maintained by part-timers, where the learning curve and complexities of web frameworks are better avoided.

so now I am wondering about whether there exists a non-mess alternative to quick-and-dirty php (not to the full-blown drupal-joomla-mvc-etc web framework alternative). perl5 (and perl6) seem like much cleaner languages. my project is even small enough that I could recode it in a day or two. BUT, if I do this, I want an embedded language with a future. are there still any good and active embedded-webpage perl communities? Mason's last update, accdg to wikipedia, was 4 years ago. embperl does not even have a wikipedia page. are they still active? is there one "quick-and-dirty" easy-ubuntu-install perl-based embedded language alternative to php, with an active development and future path to perl6, that is worth switching to and which is/has become the standard for this purpose?

opinions and advice appreciated.

/iaw

Replies are listed 'Best First'.
Re: perl as a php alternative
by Your Mother (Chancellor) on Dec 05, 2015 at 04:16 UTC

    Mason is complete and non-buggy; no particular reason for updates other than the Perl under it. PHP’s entire approach is a mess and that includes embedded code. This is why not very many of us use Mason and haven’t for a decade: it encourages a PHP-like approach. If you really like that style of code, use PHP. It drives a ton of important sites and with some discipline can be clean.

    If you want to see how powerful and easy web programming can be… Catalyst, Mojolicious, Dancer2, DBIx::Class, PSGI, uwsgi+perl, etc. Learning curve but great communities, great testing tools, good awareness of best practices and security. Worth it for the long haul. Maybe not for a one-off.

      I am going to investigate Mason and Mojolicious Lite. Do they have built-in first-class session support? In file1.php
      <?php session_start(); $_SESSION['hello']=23; ?>
      and in file2.php
      <?php session_start(); echo $_SESSION['hello']; ?>
      does exactly what one expects, as long as the browser remains the same. php nicely takes care of sending a random cookie at the right time of the http protocol, and stores the 'hello' variable in the thereby-named disk file on the server. I know I can write this myself, but this reinvents a painful wheel. transparent variable persistence across different webpages is quite nice.

      there? not there?

        I did say that they all (all major Perl web frameworks) have sessions; and not only that but they are more secure without trying in Mojo and entirely configurable in a case like Catalyst so you can do sessions without cookies if necessary and keep the data on the backend in several different ways without any need for a database, again if necessary or preferable. I feel like you are intentionally reading my comments lightly. :|

        I also said if you want to use Mason because you like embedded code, you might as well stick with PHP. There will be no practical difference in what you do if that is the style you like and deployment will be harder with Perl than host default PHP. I should re-emphasize code embedded templates (meaning, controllers and models are all embedded in the view) is a mess for any serious project and it might come off snooty but it's not meant to be: I do not know any devs I consider serious or competent who write Perl this way. If you try to write it that way, you might end up blaming Perl for giving you the rope and moving on to Python or Ruby next because they force better practices in this domain.

        I want to repeat learning curve. Catalyst in particular is quite hard to learn because it has so much it can do. Once a site is done though, adding features, changing things, testing (Mojo has really good testing too and Dancer is well-liked though I don't use it), all becomes extremely easy and make painting yourself into codebase corners less likely.

        In Dancer, you can do
        session hello => 42;

        and later

        my $hello = session 'hello';

        In config.yml, you can specify what kind of session storage you want to use: simple, cookie, storable, or YAML. The later ones are persistent.

        ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,
Re: perl as a php alternative
by hippo (Abbot) on Dec 05, 2015 at 12:17 UTC
    so now I am wondering about whether there exists a non-mess alternative to quick-and-dirty php (not to the full-blown drupal-joomla-mvc-etc web framework alternative).

    Indeed there are such alternatives. I would suggest that you take a look at one of the lightweight CGI wrappers (CGI::Lite, CGI::Minimal, CGI::Simple, etc.) add FCGI if you want persistence and then use something like Template to handle the display of the results in HTML. This can be straightforward, with nowhere near the learning curve of some of the heavy frameworks and yet provides better security than putting your code inside the documents. You can still do this with Embperl (which does appear to be alive and well) instead if you prefer.

    There are so many ways to approach this sort of task in Perl, but really only one in PHP. That's part of the joy of Perl - welcome to our world.

Re: perl as a php alternative
by ctilmes (Vicar) on Dec 05, 2015 at 14:14 UTC
        thanks, everyone. wikipedia is indeed a first goto source for me before I investigate anything further.

        I played with mojo 3 years ago and thought it was very clever. too clever for my needs. sometimes simple is good.

        the "many choices" is not always the best. I think this is why php survived. there was no one single perly choice with good prospects. (there are many abandoned projects; building a website requires betting on the underlying framework.) of course, at some point below, variety must stop. perl would not have succeeded with 20 projects. there is one perl5 project and one perl6 project.

        so, if I start now, let's say I want a php-like embeddable scripting language that has:

        1. a project with more than 5 core developers and likely survival for a decade.
        2. perl6 syntax and perl6 cpan
        3. $_SESSIONS[]
        4. easy ubuntu install
        is there a project that checks these four boxes? mojo? /iaw
Re: perl as a php alternative
by graff (Chancellor) on Dec 05, 2015 at 19:34 UTC
    I think CGI::Application is worth mentioning too. I've used it for a relatively elaborate application, and it's very handy. Easy to grok, quick and compact in terms of setup / maintenance / app expansion, good integration with your choice of templating systems.
Re: perl as a php alternative
by QuillMeantTen (Friar) on Dec 05, 2015 at 10:28 UTC

    I can only speak for Catalyst since I used it, I still have a wee bit of a hard time to grok the MVC model but its use is quite simple, there are a lot of tutorials out there and deployment is a breeze. I recommend it full-heartedly

Re: perl as a php alternative
by karlgoethebier (Prior) on Dec 06, 2015 at 13:01 UTC
Re: perl as a php alternative
by Anonymous Monk on Dec 05, 2015 at 04:02 UTC

    Mason's last update, accdg to wikipedia, was 4 years ago.

    hahah, wikipedia as a goto source of information on active projects, brilliant :p

      wikipedia is better now...because I updated the date.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1149446]
Approved by planetscape
Front-paged by Old_Gray_Bear
help
Chatterbox?
and the fire pops...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2017-12-17 23:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What programming language do you hate the most?




















    Results (466 votes). Check out past polls.

    Notices?