Fetch a single journal entry

brian_d_foy on 2002-11-14T21:24:39

I continue to improve my terminal use.perl reader. I needed a bit to fetch a single entry. It is my previous script which the looping stuff cut out and a command line argument added. Of course, this should be a module, but I don't want to write another module at the moment. Let someone else do that. :)

#!/usr/bin/perl -w
use strict;

=head1 NAME

use_journal - get a single entry from a use.perl journal

=head1 SYNOPSIS

% use_journal ID

=head1 DESCRIPTION

This script fetches a single journal entry by its entry ID. I wrote it so other programs could shell out to it to fetch an entry.

=head1 AUTHOR

brian d foy, Ebdfoy@cpan.orgE

=head1 COPYRIGHT

Copyright 2002, brian d foy, All rights reserved.

You may use this script under the same terms as Perl itself

=cut

use File::Spec::Functions; use SOAP::Lite; use Text::Template;

my $id = $ARGV[0];

die "The entry ID must be a string on digits only\n" if $id =~ m/\D/;

my $Debug = $ENV{USE_PERL_JOURNAL_DEBUG} || 0; my $Template = $ENV{USE_PERL_JOURNAL_TEMPLATE} || catfile( $ENV{HOME}, ".journal.tmpl" );

die "Could not open template file\n" unless -r $Template;

my $host = 'use.perl.org'; my $uri = "http://$host/Slash/Journal/SOAP"; my $proxy = "http://$host/journal.pl";

my $journal = SOAP::Lite->uri( $uri )->proxy( $proxy ); my $template = Text::Template->new( SOURCE => $Template );

my $hash = $journal->get_entry( $id )->result;

die "No journal entry for $id\n" unless $hash;

print $template->fill_in( HASH => { entry => $hash } );