Permalink
Browse files

add CPANPLUS glue (it works!)

  • Loading branch information...
1 parent 3d64e47 commit 5e1923b1ade0a80bc4a70e26615008f08f4fd0ae @jrockway committed Nov 16, 2007
Showing with 96 additions and 0 deletions.
  1. +60 −0 lib/CPANPLUS/Dist/PidginStatusMessage.pm
  2. +36 −0 lib/Pidgin/Status/CPAN.pm
@@ -0,0 +1,60 @@
+package CPANPLUS::Dist::PidginStatusMessage;
+use Moose;
+use Pidgin::Status::CPAN;
+
+extends 'CPANPLUS::Dist::Base';
+
+has 'pidgin_status' => (
+ isa => 'Pidgin::Status::CPAN',
+ is => 'rw',
+ #default => sub { Pidgin::Status::CPAN->new },
+ handles => {
+ set_pidgin_installing => 'installing',
+ set_pidgin_done => 'done',
+ },
+);
+
+before 'init' => sub {
+ my $self = shift; # hack around the fact that new never gets called
+ $self->pidgin_status(Pidgin::Status::CPAN->new);
+};
+
+before 'prepare' => sub {
+ my $self = shift;
+ $self->pidgin_status->installing($self->parent->author->cpanid,
+ $self->parent->module);
+};
+
+after 'install' => sub {
+ my $self = shift;
+ $self->pidgin_status->done;
+};
+
+
+1;
+
+__END__
+
+=head1 NAME
+
+CPANPLUS::Dist::PidginStatusMessage - cpanplus interface for
+Pidgin::Status::CPAN
+
+=head1 SYNOPSIS
+
+To use this module, type this at the CPANPLUS prompt:
+
+ s conf dist_type CPANPLUS::Dist::PidginStatusMessage; s save;
+
+Then you can use CPANPLUS normally, and it will update Pidgin for you.
+
+=head1 BUGS
+
+Due to the internals of CPANPLUS, this kills other dist modules like
+DEB and PAR, so if you want those to work, don't use this module.
+
+=head1 SEE ALSO
+
+L<Pidgin::Status::CPAN>
+
+
View
@@ -1,4 +1,40 @@
package Pidgin::Status::CPAN;
+use Moose;
+use Pidgin::Status::CPAN::Manager;
+use utf8;
+
+has 'status_manager' => (
+ isa => 'Pidgin::Status::CPAN::Manager',
+ is => 'ro',
+ default => sub { Pidgin::Status::CPAN::Manager->new },
+ handles => [qw/restore_message set_message/],
+);
+
+has 'format_string' => (
+ isa => 'Str',
+ is => 'ro',
+ default => '⚙ Now installing: %author - %dist',
+);
+
+sub installing {
+ my ($self, $author, $dist) = @_;
+ my $message = $self->_format($author, $dist);
+ $self->set_message($message); # TODO: time delay?
+}
+
+sub _format {
+ my ($self, $author, $dist) = @_;
+ my $message = $self->format_string;
+ $message =~ s/\%\%/%/g; # Foo %% => Foo %
+ $message =~ s/\%author/$author/g; # Foo %author = Foo PAUSE_ID
+ $message =~ s/\%dist/$dist/g;
+ return $message;
+}
+
+sub done {
+ my $self = shift;
+ $self->restore_message;
+}
1;

0 comments on commit 5e1923b

Please sign in to comment.