blib/lib/App/Maisha.pm

filter: Statementstmt 93.3% 70 / 75 Branchbran 90.0% 18 / 20 Conditioncond 72.7% 8 / 11 MC/DCmcdc 50.0% 3 / 6 Subroutinesub 91.6% 11 / 12 Podpod 100% 4 / 4 totaltotal 89.0% 114 / 128 CC 17 SCAR 19.9
CC
17
Cov
91%
setup
13.0
load_config
5.1
run
2.0
CRAP 7.3
« blib/lib/App/Maisha/Shell.pm ↑ Summary blib/lib/App/Maisha/Plugin/Base.pm »
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
BranchTrueFalseTotal
if ($config and not ref $config) 6 1 7
Condition66%2/3
$config and not ref $config
!ll&&!rl&&r
016
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
ABresult
0X0
100
111
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
BranchTrueFalseTotal
unless $config 0 5 5
72 5 ▶ croak("Maisha expectes a config file that can be decoded to a HASH") if(ref $config ne 'HASH');
Branch: 1 branch
BranchTrueFalseTotal
if ref $config ne "HASH" 0 5 5
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
l!l
05
MC/DC0%0/1
$config->{'CONFIG'}{'debug'} || 0
$config->{'CONFIG'}{'debug'}
Truth table50%1/2
A
A= $config->{'CONFIG'}{'debug'}
Aresult
11
00
87 5 ▶ my $history = $config->{CONFIG}{history} || '';
Condition50%1/2
$config->{'CONFIG'}{'history'} || ''
l!l
05
MC/DC0%0/1
$config->{'CONFIG'}{'history'} || ''
$config->{'CONFIG'}{'history'}
Truth table50%1/2
A
A= $config->{'CONFIG'}{'history'}
Aresult
11
00
88  
89 5 my $tag = $config->{CONFIG}{tag};
90 5 ▶ $tag ||= '[from maisha]';
Condition100%2/2
$tag ||= "[from maisha]"
l!l
32
MC/DC100%1/1
$tag ||= "[from maisha]"
$tag
Truth table100%2/2
A
A= $tag
Aresult
11
00
91 5 ▶ $tag = '' if($tag eq '.');
Branch: 1 branch
BranchTrueFalseTotal
if $tag eq "." 2 3 5
92  
93 5 my $prompt = $config->{CONFIG}{prompt};
94 5 ▶ $prompt ||= 'maisha>';
Condition100%2/2
$prompt ||= "maisha>"
l!l
14
MC/DC100%1/1
$prompt ||= "maisha>"
$prompt
Truth table100%2/2
A
A= $prompt
Aresult
11
00
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
BranchTrueFalseTotal
defined $config->{'CONFIG'}{'pager'} ? : 1 4 5
103 5 ▶ $shell->order( defined $config->{CONFIG}{order} ? $config->{CONFIG}{order} : 'descending');
Branch: 1 branch
BranchTrueFalseTotal
defined $config->{'CONFIG'}{'order'} ? : 3 2 5
104 5 ▶ $shell->limit( defined $config->{CONFIG}{limit} ? $config->{CONFIG}{limit} : 0);
Branch: 1 branch
BranchTrueFalseTotal
defined $config->{'CONFIG'}{'limit'} ? : 1 4 5
105 5 ▶ $shell->chars( defined $config->{CONFIG}{chars} ? $config->{CONFIG}{chars} : 80);
Branch: 1 branch
BranchTrueFalseTotal
defined $config->{'CONFIG'}{'chars'} ? : 1 4 5
106 5 ▶ $shell->format(defined $config->{CONFIG}{format} ? $config->{CONFIG}{format} : '[%U] %M');
Branch: 1 branch
BranchTrueFalseTotal
defined $config->{'CONFIG'}{'format'} ? : 1 4 5
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
BranchTrueFalseTotal
if $plugin eq "CONFIG" 5 2 7
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__
« blib/lib/App/Maisha/Shell.pm ↑ Summary blib/lib/App/Maisha/Plugin/Base.pm »