車椅子のCOBOL:COBOL用マイクロ・ウェブ・フレームワーク

COBOL on Wheelchair: A Minimal Web Framework for the Brave

COBOL on Wheelchair is a proof of concept web framework that challenges the notion that COBOL, a programming language developed in the 1950s, is outdated and irrelevant in today’s fast-paced web development world. Created by Adrian Zandberg, a self-proclaimed 54-year-old dog eager to learn new tricks, COBOL on Wheelchair may not be the most sophisticated web framework out there, but it certainly has its charm.

To run COBOL on Wheelchair, you will need:

  • A working installation of COBOL
  • A web server (Apache is recommended)

The framework comes with a .htaccess file for Apache, so if you’re on Linux, you shouldn’t have to worry about configuring your server. Simply point your browser to the appropriate URL, and if all goes well, you should see a simple “Hello world” message.

The directory structure of COBOL on Wheelchair is straightforward. It consists of:

  • A config.cbl file for routing
  • A controllers directory for holding COBOL logic
  • A views directory for templates

Routing in COBOL on Wheelchair is set in the config.cbl file using two tables. The routing-pattern table holds the paths, while the routing-destiny table holds the names of the attached controllers (COBOL subprograms).

For example, to send users visiting server.com/example/path to the “myroutine1” controller, you would add the following code to config.cbl:

SET routing-pattern(1) TO "example/path"
SET routing-destiny(1) TO "myroutine1"

You can also accept variables from the path by using curly braces:

SET routing-pattern(2) TO "example/{val1}/path/{val2}"
SET routing-destiny(2) TO "myroutine2"

COBOL on Wheelchair allows you to set up to 99 routes, each with its own controller located in the controllers directory. A basic controller looks like this:

IDENTIFICATION DIVISION.
PROGRAM-ID. myroutine1.

DATA DIVISION.
WORKING-STORAGE SECTION.
77 the-values PIC X(50) OCCURS 10 TIMES.

PROCEDURE DIVISION.
    PERFORM VARYING i FROM 1 BY 1 UNTIL i > 10
        DISPLAY "Value " i ": " the-values(i)
    END-PERFORM.

    STOP RUN.

In this example, the controller accesses variables received from the path through the the-values table. The order of the variables in the path corresponds to the order in which they appear in the table.

To utilize templates, you need to prepare variables and call the templating engine from the controller. Templates are located in the views directory and consist of simple HTML files with variables enclosed in double curly braces.

For example, to use the “Hello World” template, you would define the variables in the working-storage section of the controller:

WORKING-STORAGE SECTION.
01 the-vars.
    05 the-vars-username PIC X(50) VALUE "{{username}}".
    05 the-vars-age PIC X(50) VALUE "{{age}}".

Then, when the variables are ready, you can invoke the templating engine using the ‘cowtemplate’ routine:

CALL "cowtemplate" USING the-vars, "hello_world.html".

In this example, the value of the variable {{username}} is set to COW-query-value(1), which corresponds to the value received from the path. The resulting HTML will inject this value into the template.

While COBOL on Wheelchair may not be production-ready or suitable for complex web applications, it serves as a testament to the versatility and adaptability of COBOL. It proves that even a language developed over half a century ago can still find its place in the modern web development landscape.

So why not give COBOL on Wheelchair a try? Who knows, you might just discover a new appreciation for this old but resilient programming language.

Contact: adrian.zandberg@gmail.com

注意

  • この記事はAI(gpt-3.5-turbo)によって自動生成されたものです。
  • この記事はHackerNewsに掲載された下記の記事を元に作成されています。
    COBOL on Wheelchair: Micro web-framework for COBOL
  • 自動生成された記事の内容に問題があると思われる場合にはコメント欄にてご連絡ください。

コメントする