File: Publish.pm

package info (click to toggle)
libcli-framework-perl 0.05-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 456 kB
  • sloc: perl: 2,168; sql: 18; sh: 3; makefile: 2
file content (57 lines) | stat: -rw-r--r-- 1,157 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package My::Journal::Command::Publish;
use base qw( CLI::Framework::Command );

use strict;
use warnings;
use Carp;

#-------

sub usage_text {
    q{
    publish [--out=<output-file> --format=<format>]: publish a journal
    }
}

sub option_spec {
    (
        [ 'format=s'      => 'publish in specific format' ],
        [ 'template=s'    => '' ],
        [ 'out=s'         => 'output file' ],
    )
}

sub run {
    my ($self, $opts, @args) = @_;

    my $db = $self->cache->get('db');
    croak "DB not initialized in cache" unless $db;

    my @entries = $db->all_entries();
    my @entries_output;
    for my $entry (@entries) {
        my $entry_output = $entry->{id}.':'.$entry->{entry_text};

        my @tags = $db->tags_by_entry_id( $entry->{id} );
        $entry_output .= ' [tags: ' . join(',', @tags) . ']' if @tags;

        push @entries_output, $entry_output;
    }
print 'Pretend that this data gets published in the ',
'requested format, using a specified template, and sent to a named ',
"output file\n\n";
    return join("\n", @entries_output) . "\n";
}

#-------
1;

__END__

=pod

=head1 PURPOSE

Command to publish a journal

=cut