File Coverage

blib/lib/App/Maisha.pm
Criterion Covered Total %
statement 70 75 93.3
branch 14 20 70.0
condition 8 11 72.7
subroutine 12 13 92.3
pod 4 4 100.0
total 108 123 87.8


line stmt bran cond sub pod time code
1             package App::Maisha;
2              
3 8     8   202907 use strict;
  8         18  
  8         302  
4 8     8   42 use warnings;
  8         15  
  8         416  
5              
6             our $VERSION = '0.21';
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     8   50 use base qw(Class::Accessor::Fast);
  8         18  
  8         7454  
35              
36 8     8   45126 use Carp qw(croak);
  8         17  
  8         477  
37 8     8   21092 use Config::Any;
  8         117825  
  8         418  
38 8     8   7615 use App::Maisha::Shell;
  8         33  
  8         490  
39 8     8   98 use File::Basename;
  8         14  
  8         978  
40 8     8   9057 use File::HomeDir;
  8         65318  
  8         9320  
41              
42             #----------------------------------------------------------------------------
43             # Accessors
44              
45             __PACKAGE__->mk_accessors($_) for qw(shell config);
46              
47             #----------------------------------------------------------------------------
48             # Public API
49              
50             sub new {
51 7     7 1 26720 my $class = shift;
52 7         69 my $self = $class->SUPER::new();
53 7         102 my $config = $self->load_config(@_);
54 4         26 $self->config($config);
55 4         45 $self->setup();
56 4         42157 $self;
57             }
58              
59             sub load_config {
60 7     7 1 27 my ($self,%hash) = @_;
61 7         18 my $config = $hash{config};
62              
63 7 100 66     55 if ($config && ! ref $config) {
64 6         15 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         93 my $list = Config::Any->load_files( { files => [ $filename ], use_ext => 1 } );
68 3         11882 ($config) = $list->[0]->{$filename};
69             }
70              
71 4 50       23 croak("Could not load configuration file") if(!$config);
72 4 50       17 croak("Maisha expectes a config file that can be decoded to a HASH") if(ref $config ne 'HASH');
73              
74             # some systems use a broken pager, so force the internal parser to be used
75 4         37 $self->{pager} = $ENV{PAGER};
76 4         55 $ENV{PAGER} = '';
77              
78 4         17 return $config;
79             }
80              
81             sub setup {
82 4     4 1 7 my $self = shift;
83 4         15 my $config = $self->config;
84 4         93 my $shell = $self->shell(App::Maisha::Shell->new);
85              
86 4   50     60565 my $debug = $config->{CONFIG}{debug} || 0;
87 4   50     46 my $history = $config->{CONFIG}{history} || '';
88              
89 4         17 my $tag = $config->{CONFIG}{tag};
90 4   100     25 $tag ||= '[from maisha]';
91 4 100       16 $tag = '' if($tag eq '.');
92              
93 4         14 my $prompt = $config->{CONFIG}{prompt};
94 4   100     28 $prompt ||= 'maisha>';
95 4         39 $prompt =~ s/\s*$/ /;
96              
97              
98 4         41 $shell->debug($debug);
99 4         19 $shell->history($history);
100 4         31 $shell->prompt_str($prompt);
101 4         20 $shell->tag_str($tag);
102 4 50       41 $shell->pager( defined $config->{CONFIG}{pager} ? $config->{CONFIG}{pager} : 1 );
103 4 100       30 $shell->order( defined $config->{CONFIG}{order} ? $config->{CONFIG}{order} : 'descending');
104 4 50       28 $shell->limit( defined $config->{CONFIG}{limit} ? $config->{CONFIG}{limit} : 0);
105 4 50       29 $shell->chars( defined $config->{CONFIG}{chars} ? $config->{CONFIG}{chars} : 80);
106 4 50       28 $shell->format(defined $config->{CONFIG}{format} ? $config->{CONFIG}{format} : '[%U] %M');
107              
108 4         74 my $home = File::HomeDir->my_home();
109              
110             # connect to the available sites
111 4         238 for my $plugin (keys %$config) {
112 6 100       28 next if($plugin eq 'CONFIG');
113 2         9 $config->{$plugin}{home} = $home;
114 2         9 $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 4     2   168 binmode STDOUT, ":encoding(UTF-8)";
  2         23  
  2         6  
  2         1083  
120             }
121              
122             sub run {
123 0     0 1 0 my $self = shift;
124 0         0 my $shell = $self->shell;
125 0         0 $shell->postcmd();
126 0         0 $shell->cmdloop();
127              
128 0         0 $ENV{PAGER} = $self->{pager};
129             }
130              
131             1;
132              
133             __END__
134              
135             =head1 METHODS
136              
137             =head2 Constructor
138              
139             =over 4
140              
141             =item * new
142              
143             =back
144              
145             =head2 Process Methods
146              
147             =over 4
148              
149             =item * load_config
150              
151             Loads the configuration file. See the 'maisha' script to see a fuller
152             description of the configuration options.
153              
154             =item * setup
155              
156             Prepares the interface and internal environment.
157              
158             =item * run
159              
160             Starts the command loop shell, and awaits your command.
161              
162             =back
163              
164             =head1 WEBSITES
165              
166             =over 4
167              
168             =item * Main Site: L<http://maisha.grango.org>
169              
170             =item * Git Repo: L<http://github.com/barbie/maisha/tree/master>
171              
172             =item * RT Queue: L<RT: http://rt.cpan.org/Public/Dist/Display.html?Name=App-Maisha>
173              
174             =back
175              
176             =head1 THANKS TO
177              
178             My thanks go to the following people for suggestions and help when putting this
179             application together.
180              
181             Dave Cross, Robert Rothenberg and Steffen Müller.
182              
183             =head1 AUTHOR
184              
185             Barbie, <barbie@cpan.org>
186             for Miss Barbell Productions <http://www.missbarbell.co.uk>.
187              
188             =head1 COPYRIGHT AND LICENSE
189              
190             Copyright (C) 2009-2014 by Barbie
191              
192             This distribution is free software; you can redistribute it and/or
193             modify it under the Artistic License v2.
194              
195             =cut