#!perl

use strict;
use warnings;

use autodie;

use Git;

use Pod::Usage;
use Getopt::Long;

sub say (@) { print @_, "\n" }

my %opt;
GetOptions( \%opt, 
    'help' => sub { pod2usage(1) },
    'man'  => sub { pod2usage( verbose => 2 ) },
) or pod2usage( "for a list of all valid options, do 'git cpan-which --help'" );

my $repo = Git->repository;

my $last_commit = $repo->command_oneline('rev-parse', '--verify', 'cpan/master');

my $last = join "\n", $repo->command( log => '--pretty=format:%b', '-n', 1, $last_commit );

$last =~ /git-cpan-module: \s+ (.*?) \s+ git-cpan-version: \s+ (.*?) \s*$/sx
    or die "Couldn't parse message:\n$last\n";

say $1;

__END__

=pod

=head1 NAME

git-cpan-last-version - Report the managed module

=head1 VERSION

version 0.4.5

=head1 SYNOPSIS

    % git cpan-which

=head1 DESCRIPTION

This command prints the name of the module tracked in C<cpan/master>.

=head1 BUGS AND LIMITATIONS

Please report any bugs or feature requests to
C<bug-git-cpan-patch@rt.cpan.org>, or through the web 
interface at L<http://rt.cpan.org>.
  
=head1 AUTHORS

Yanick Champoux C<< <yanick@cpan.org> >>

Yuval Kogman C<< <nothingmuch@woobling.org> >>

=head1 LICENCE

This module is free software; you can redistribute it and/or
modify it under the same terms as Perl itself. See L<perlartistic>.

=head1 SEE ALSO

L<Git::CPAN::Patch>

=cut