| 1 | package App::Maisha; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 8 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 8 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 8 | our $VERSION = '0.22'; | |||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | #---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | =encoding utf8 | ||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | =head1 NAME | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | App::Maisha - A command line social micro-blog networking tool. | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | use App::Maisha; | ||||||||||||||||||||||||||||
| 19 | my $maisha = App::Maisha->new(config => $file)->run; | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | This distribution provides the ability to micro-blog via social networking | ||||||||||||||||||||||||||||
| 24 | websites and services, such as Identica and Twitter. | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | For further information regarding the commands and configuration, please see | ||||||||||||||||||||||||||||
| 27 | the 'maisha' script included with this distribution. | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | =cut | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | #---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 32 | # Library Modules | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 8 | ▶ | use base qw(Class::Accessor::Fast); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 8 | ▶ | use Carp qw(croak); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 37 | 8 | ▶ | use Config::Any; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 38 | 8 | ▶ | use App::Maisha::Shell; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 39 | 8 | ▶ | use File::Basename; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 40 | 8 | ▶ | use File::HomeDir; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | #---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 43 | # Accessors | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 8 | __PACKAGE__->mk_accessors($_) for qw(shell config); | |||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | #---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 48 | # Public API | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 7 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 51 | 7 | my $class = shift; | |||||||||||||||||||||||||||
| 52 | 7 | my $self = $class->SUPER::new(); | |||||||||||||||||||||||||||
| 53 | 7 | my $config = $self->load_config(@_); | |||||||||||||||||||||||||||
| 54 | 5 | $self->config($config); | |||||||||||||||||||||||||||
| 55 | 5 | $self->setup(); | |||||||||||||||||||||||||||
| 56 | 5 | $self; | |||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 7 | ▶ | sub load_config { | ||||||||||||||||||||||||||
|
Subroutine
load_config: called CC=5 SCAR=16.3
Pod
documented
| |||||||||||||||||||||||||||||
| 60 | 7 | my ($self,%hash) = @_; | |||||||||||||||||||||||||||
| 61 | 7 | my $config = $hash{config}; | |||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 7 | ▶ | if ($config && ! ref $config) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$config and not ref $config
MC/DC50%1/2
$config and not ref $config
$config
not ref $config
Truth table66%2/3
A and not(B)
A= $configB= not ref $config
| |||||||||||||||||||||||||||||
| 64 | 6 | my $filename = $config; | |||||||||||||||||||||||||||
| 65 | # In the future, we may support multiple configs, but for now | ||||||||||||||||||||||||||||
| 66 | # just load a single file via Config::Any | ||||||||||||||||||||||||||||
| 67 | 6 | my $list = Config::Any->load_files( { files => [ $filename ], use_ext => 1 } ); | |||||||||||||||||||||||||||
| 68 | 4 | ($config) = $list->[0]->{$filename}; | |||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 5 | ▶ | croak("Could not load configuration file") if(!$config); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 72 | 5 | ▶ | croak("Maisha expectes a config file that can be decoded to a HASH") if(ref $config ne 'HASH'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | # some systems use a broken pager, so force the internal parser to be used | ||||||||||||||||||||||||||||
| 75 | 5 | $self->{pager} = $ENV{PAGER}; | |||||||||||||||||||||||||||
| 76 | 5 | $ENV{PAGER} = ''; | |||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 5 | return $config; | |||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 5 | ▶ | sub setup { | ||||||||||||||||||||||||||
|
Subroutine
setup: called CC=13 SCAR=25.7
Pod
documented
| |||||||||||||||||||||||||||||
| 82 | 5 | my $self = shift; | |||||||||||||||||||||||||||
| 83 | 5 | my $config = $self->config; | |||||||||||||||||||||||||||
| 84 | 5 | my $shell = $self->shell(App::Maisha::Shell->new); | |||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 5 | ▶ | my $debug = $config->{CONFIG}{debug} || 0; | ||||||||||||||||||||||||||
|
Condition50%1/2
$config->{'CONFIG'}{'debug'} || 0
MC/DC0%0/1
$config->{'CONFIG'}{'debug'} || 0
$config->{'CONFIG'}{'debug'}
Truth table50%1/2
A
A= $config->{'CONFIG'}{'debug'}
| |||||||||||||||||||||||||||||
| 87 | 5 | ▶ | my $history = $config->{CONFIG}{history} || ''; | ||||||||||||||||||||||||||
|
Condition50%1/2
$config->{'CONFIG'}{'history'} || ''
MC/DC0%0/1
$config->{'CONFIG'}{'history'} || ''
$config->{'CONFIG'}{'history'}
Truth table50%1/2
A
A= $config->{'CONFIG'}{'history'}
| |||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 5 | my $tag = $config->{CONFIG}{tag}; | |||||||||||||||||||||||||||
| 90 | 5 | ▶ | $tag ||= '[from maisha]'; | ||||||||||||||||||||||||||
|
Condition100%2/2
$tag ||= "[from maisha]"
MC/DC100%1/1
$tag ||= "[from maisha]"
$tag
Truth table100%2/2
A
A= $tag
| |||||||||||||||||||||||||||||
| 91 | 5 | ▶ | $tag = '' if($tag eq '.'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 5 | my $prompt = $config->{CONFIG}{prompt}; | |||||||||||||||||||||||||||
| 94 | 5 | ▶ | $prompt ||= 'maisha>'; | ||||||||||||||||||||||||||
|
Condition100%2/2
$prompt ||= "maisha>"
MC/DC100%1/1
$prompt ||= "maisha>"
$prompt
Truth table100%2/2
A
A= $prompt
| |||||||||||||||||||||||||||||
| 95 | 5 | $prompt =~ s/\s*$/ /; | |||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 5 | $shell->debug($debug); | |||||||||||||||||||||||||||
| 99 | 5 | $shell->history($history); | |||||||||||||||||||||||||||
| 100 | 5 | $shell->prompt_str($prompt); | |||||||||||||||||||||||||||
| 101 | 5 | $shell->tag_str($tag); | |||||||||||||||||||||||||||
| 102 | 5 | ▶ | $shell->pager( defined $config->{CONFIG}{pager} ? $config->{CONFIG}{pager} : 1 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 103 | 5 | ▶ | $shell->order( defined $config->{CONFIG}{order} ? $config->{CONFIG}{order} : 'descending'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 104 | 5 | ▶ | $shell->limit( defined $config->{CONFIG}{limit} ? $config->{CONFIG}{limit} : 0); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 105 | 5 | ▶ | $shell->chars( defined $config->{CONFIG}{chars} ? $config->{CONFIG}{chars} : 80); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 106 | 5 | ▶ | $shell->format(defined $config->{CONFIG}{format} ? $config->{CONFIG}{format} : '[%U] %M'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 5 | my $home = File::HomeDir->my_home(); | |||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | # connect to the available sites | ||||||||||||||||||||||||||||
| 111 | 5 | for my $plugin (keys %$config) { | |||||||||||||||||||||||||||
| 112 | 7 | ▶ | next if($plugin eq 'CONFIG'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 113 | 2 | $config->{$plugin}{home} = $home; | |||||||||||||||||||||||||||
| 114 | 2 | $self->shell->connect($plugin,$config->{$plugin}); | |||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | # in some environments 'Wide Character' warnings are emited where unicode | ||||||||||||||||||||||||||||
| 118 | # strings are seen in status messages. This suppresses them. | ||||||||||||||||||||||||||||
| 119 | 5 | binmode STDOUT, ":encoding(UTF-8)"; | |||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | 0 | ▶ | sub run { | ||||||||||||||||||||||||||
|
Subroutine
run: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 123 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 124 | 0 | my $shell = $self->shell; | |||||||||||||||||||||||||||
| 125 | 0 | $shell->postcmd(); | |||||||||||||||||||||||||||
| 126 | 0 | $shell->cmdloop(); | |||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | 0 | $ENV{PAGER} = $self->{pager}; | |||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | 8 | 1; | |||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | __END__ | ||||||||||||||||||||||||||||