App-MatrixClient

 view release on metacpan or  search on metacpan

lib/App/MatrixClient.pm  view on Meta::CPAN

{
   my $self = shift;
   my ( $line, $tab ) = @_;

   # For now all commands are simple methods on __PACKAGE__
   my ( $cmd, @args ) = split m/\s+/, $line;

   $tab->append_line(
      String::Tagged->new( '$ ' . join " ", $cmd, @args )
         ->apply_tag( 0, -1, fg => "cyan" )
   );

   my $method = "cmd_$cmd";
   $self->{cmd_f} = Future->call( sub { $self->$method( @args ) } )
      ->on_done( sub {
         my @result = @_;
         $tab->append_line( $_ ) for @result;

         undef $self->{cmd_f};
      })
      ->on_fail( sub {
         my ( $failure ) = @_;

         $tab->append_line(
            String::Tagged->new( "Error: $failure" )
               ->apply_tag( 0, -1, fg => "red" )
         );

         undef $self->{cmd_f};
      });
}


## Command handlers

sub cmd_dname_get
{
   my $self = shift;
   my ( $user_id ) = @_;

   $self->{dist}->fire_async( do_get_displayname => $user_id );
}

sub cmd_dname_set
{
   my $self = shift;
   my ( $name ) = @_;

   $self->{dist}->fire_async( do_set_displayname => $name )
      ->then_done( "Set" );
}

sub cmd_offline
{
   my $self = shift;

   $self->{dist}->fire_async( do_set_presence => "offline", @_ )
      ->then_done( "Set" );
}

sub cmd_busy
{
   my $self = shift;

   $self->{dist}->fire_async( do_set_presence => "unavailable", "Busy" )
      ->then_done( "Set" );
}

sub cmd_away
{
   my $self = shift;

   $self->{dist}->fire_async( do_set_presence => "unavailable", "Away" )
      ->then_done( "Set" );
}

sub cmd_online
{
   my $self = shift;

   $self->{dist}->fire_async( do_set_presence => "online", @_ )
      ->then_done( "Set" );
}

sub cmd_createroom
{
   my $self = shift;
   my ( $room_name ) = @_;

   $self->{dist}->fire_async( do_room_create => $room_name )->then( sub {
      my ( $response ) = @_;
      Future->done( pp($response) );
   });
}

sub cmd_join
{
   my $self = shift;
   my ( $room_name ) = @_;

   $self->{dist}->fire_async( do_room_join => $room_name )
      ->then_done( "Joined" );
}

sub cmd_leave
{
   my $self = shift;
   my ( $roomid ) = @_;

   $self->{dist}->fire_async( do_room_leave => $roomid )
      ->then_done( "Left" );
}

sub cmd_msg
{
   my $self = shift;
   my ( $roomid, @msg ) = @_;

   my $msg = join " ", @msg;

   $self->{dist}->fire_async( do_room_msg => $roomid, $msg )



( run in 1.893 second using v1.01-cache-2.11-cpan-39bf76dae61 )