App-Maisha
view release on metacpan or search on metacpan
lib/App/Maisha/Shell.pm view on Meta::CPAN
package App::Maisha::Shell;
use strict;
use warnings;
our $VERSION = '0.22';
#----------------------------------------------------------------------------
=head1 NAME
App::Maisha::Shell - A command line social micro-blog networking tool.
=head1 SYNOPSIS
use App::Maisha::Shell;
my $shell = App::Maisha::Shell->new;
=head1 DESCRIPTION
This distribution provides the ability to micro-blog via social networking
websites and services, such as Identica and Twitter.
=cut
#----------------------------------------------------------------------------
# Library Modules
use base qw(Term::Shell);
use File::Basename;
use File::Path;
use IO::File;
use Module::Pluggable instantiate => 'new', search_path => ['App::Maisha::Plugin'];
use Text::Wrap;
#----------------------------------------------------------------------------
# Variables
$Text::Wrap::columns = 80;
my %plugins; # contains all available plugins
my %months = (
'Jan' => 1, 'Feb' => 2, 'Mar' => 3, 'Apr' => 4,
'May' => 5, 'Jun' => 6, 'Jul' => 7, 'Aug' => 8,
'Sep' => 9, 'Oct' => 10, 'Nov' => 11, 'Dec' => 12,
);
my %max = (
user_timeline => { limit => 3200, count => 200 }, # specific user timelines
search_tweets => { limit => 800, count => 100 }, # search lists
home_timeline => { limit => 800, count => 200 }, # generic timelines
user_lists => { limit => 5000, count => 5000 }, # user lists
);
#----------------------------------------------------------------------------
# Accessors
sub networks { shift->_elem('networks', @_) }
sub prompt_str { shift->_elem('prompt_str', @_) }
sub tag_str { shift->_elem('tag_str', @_) }
sub order { shift->_elem('order', @_) }
sub limit { shift->_elem('limit', @_) }
sub services { shift->_elem('services', @_) }
sub pager { shift->_elem('pager', @_) }
sub format { shift->_elem('format', @_) }
sub chars { shift->_elem('chars', @_) }
sub history { shift->_elem('historyfile', @_) }
sub debug { shift->_elem('debug', @_) }
sub error { shift->_elem('error', @_) }
#----------------------------------------------------------------------------
# Public API
#
# Connect/Disconnect
#
sub connect {
my ($self,$plug,$config) = @_;
unless($plug) { warn "No plugin supplied\n"; return }
$self->_load_plugins unless(%plugins);
my $plugin = $self->_get_plugin($plug);
if(!$plugin) {
warn "Unable to establish plugin '$plug'\n";
return;
}
my $status = $plugin->login($config);
if(!$status) {
warn "Login to '$plug' failed\n";
return;
}
my $services = $self->services;
push @$services, $plugin;
$self->services($services);
$self->_reset_networks;
}
*run_connect = \&connect;
sub smry_connect { "connect to a service" }
sub help_connect {
<<'END';
Connects to a named service. Requires the name of the service, together with
the username and password to access the service.
END
}
sub run_disconnect {
my ($self,$plug) = @_;
unless($plug) { warn "No plugin supplied\n"; return }
my $services = $self->services;
my @new = grep {ref($_) !~ /^App::Maisha::Plugin::$plug$/} @$services;
lib/App/Maisha/Shell.pm view on Meta::CPAN
my $pages = int($limit / $count) + ($limit % $count ? 1 : 0);
return($limit,$pages,$count);
}
sub _load_plugins {
my $self = shift;
for my $plugin ($self->plugins()) {
my $class = ref($plugin);
$class =~ s/^App::Maisha::Plugin:://;
#print STDERR "CLASS=$class, PLUGIN=$plugin\n";
$plugins{$class} = $plugin unless($class eq 'Base');
}
}
sub _get_plugin {
my $self = shift;
my $class = shift or return;
return $plugins{$class} || undef;
}
1;
__END__
=head1 METHODS
=head2 Constructor
=over 4
=item * new
=back
=head2 Configuration Methods
=over 4
=item * context
Used internally to reference the current shell for command handlers.
=item * limit
Used by timeline commands to limit the number of messages displayed. The
default setting will display the last 20 messages.
=item * order
Used by timeline commands to order the messages displayed. The default is to
display messages in descending order, with the most recent first and the oldest
last.
To reverse this order, set the 'order' as 'ascending' (or 'asc') in your
configuration file. (case insensitive).
=item * networks
Sets the networks list that will appear above the command line.
=item * prompt_str
Sets the prompt string that will appear on the command line.
=item * tag_str
Sets the text that will appear at the end of your message.
In order to suppress the tag string set the 'tag' option to '.' in your
configuration file.
=item * services
Provides the order of services available, the first is always the primary
service.
=item * pager
Enables the use of a pager when viewing timelines. Defaults to true
if not specified.
=item * format
When printing a list of status messages, the default format of printing the
username followed by the status message is not always suitable for everyone. As
such you can define your own formatting.
The default format is "[%U] %M", with the available formatting patterns defined
as:
%U - username or screen name
%M - status message
%T - timestamp (e.g. Sat Oct 13 19:29:17 +0000 2012)
%D - datetime (e.g. 13/10/2012 19:29:17)
%d - date only (e.g. 13/10/2012)
%t - time only (e.g. 19:29:17)
%N - network
=item * chars
As Maisha is run from the command line, it is most likely being run within a
terminal window. Unfortunately there isn't currently a detection method for
knowing the exact screen width being used. As such you can specify a width for
the wrapper to use to ensure the messages are correctly line wrapped. The
default setting is 80.
=item * history
Provides the history file, if available.
=item * debug
Boolean setting for debugging messages.
=item * error
The last error message received from a failing command.
=back
=head2 Run Methods
The run methods are handlers to run the specific command requested.
( run in 1.233 second using v1.01-cache-2.11-cpan-6aa56a78535 )