package App::Changelord; use 5.36.0; use Moo; use CLI::Osprey; use YAML; option source => ( is => 'ro', doc => 'changelog yaml file', default => 'CHANGELOG.yml', ); has changelog => ( lazy => 1, is => 'ro', default => sub($self) { return YAML::LoadFile($self->source) } ); sub render_header($self) { my $output = "# Changelog"; my $name = $self->changelog->{project}{name}; my %links = (); if( $self->changelog->{project}{homepage} ) { $name = "[$name][homepage]"; $links{homepage} = $self->changelog->{project}{homepage}; } $output .= " for $name" if $name; if(%links) { $output .= "\n\n"; $output .= $self->render_refs(%links); } $output .= "\n\n"; } sub render_refs($self,%links) { my $output = ''; for my $ref ( sort keys %links ) { $output .= " [$ref]: $links{$ref}\n" } return $output . "\n"; } sub as_markdown($self) { my $changelog = $self->changelog; my $output = $self->render_header; my $n = 0; $output .= join "\n", map { $self->render_release($_, $n++) } $changelog->{releases}->@*; return $output; } sub render_release($self, $release, $n=0) { # it's a string? Okay then! return $release unless ref $release; my $version = $release->{version} || ( $n ? '???' : 'NEXT' ); my $date = $release->{date}; my $output = ''; $output .= "## $version"; $output .= " ($date)" if $date; return $output; } sub run($self) { no warnings 'utf8'; print $self->as_markdown; } subcommand 'schema' => 'App::Changelord::Command::Schema'; subcommand 'validate' => 'App::Changelord::Command::Validate'; 'end of App::Changeman';