What's the best way to write a Perl CGI application?

后端 未结 6 1126
轮回少年
轮回少年 2021-02-14 10:10

Every example I\'ve seen of CGI/Perl basically a bunch of print statements containing HTML, and this doesn\'t seem like the best way to write a CGI app. Is there a better way t

6条回答
  •  一生所求
    2021-02-14 10:37

    This is a really, really big question. In short, the better way is called Model/View/Controller (aka MVC). With MVC, your application is split into three pieces.

    The Model is your data and business logic. It's the stuff that makes up the core of your application.

    The View is the code for presenting things to the user. In a web application, this will typically be some sort of templating system, but it could also be a PDF or Excel spreadsheet. Basically, it's the output.

    Finally, you have the Controller. This is responsible for putting the Model and View together. It takes a user's request, gets the relevant model objects, and calls the appropriate view.

    mpeters already mentioned several MVC frameworks for Perl. You'll also want to pick a templating engine. The two most popular are Template Toolkit and Mason.

提交回复
热议问题