App::Sp...Tutorial(3)

πŸ“¦ version 0.15.0, in opensuse-leap 16.0

hey bestie πŸ’– this is App::Sp...Tutorial(3) β€” the User Contributed Perl Documentation page for App::Spec::Tutorial. It’s literally the tutorial for how to write an app with App::Spec::Run. Main character energy for your CLI, no cap. ✨

🌸 NAME 🌸

App::Spec::Tutorial β€” how to write an app with App::Spec::Run. That’s the whole name, bestie, and it ate. πŸ’…


πŸ’– Options and parameters πŸ’–

See App::Spec::Argument for the documentation and examples on how to define options and parameters. Go peek, iykyk. 🫢


πŸ› οΈ GENERATOR πŸ› οΈ

You can generate a boilerplate with appspec:

appspec new --class App::Birthdays --name birthdays.pl

For documentation, look at appspec and App::AppSpec. They’re the ones with the lore. πŸ“šβœ¨


🌈 EXAMPLES 🌈

πŸŽ‚ A minimal app called birthdays.pl πŸŽ‚

The smallest example would be the following app. It doesn’t use subcommands β€” literally zero subcommands, none, nada. πŸŽ€

🧁 birthdays.pl 🧁

use strict;
use warnings;
package App::Birthdays;
use base 'App::Spec::Run::Cmd';

sub execute {
    my ($self, $run) = @_;
    my $date = $run->options->{date};
    my $output = <<"EOM";
Birthdays $date:

EOM
    $output .= "Larry Wall";
    if ($run->options->{age}) {
        $output .= " (Age: unknown)";
    }
    $output .= "\n";
    $run->out($output);
}

package main;
use App::Spec;

App::Spec->read("$Bin/birthdays.yaml")->runner->run;

πŸ“ birthdays.yaml πŸ“

Short version:

name: birthdays.pl
title: Show birthdays
appspec: { version: '0.001' }
class: App::Birthdays
options:
- date=s =today --Date
- age           --Show age

Long version:

name: birthdays.pl
title: Show birthdays
appspec: { version: '0.001' }
class: App::Birthdays
options:
- name: date
  type: string
  default: today
  summary: Date
- name: age
  type: flag
  summary: Show age

And that’s the whole page, bestie β€” perl v5.42.0, dated 2025-03-26, from App::Sp...Tutorial(3). Slay your CLI era πŸ’œβœ¨

πŸ“¦ where this page comes from