File Coverage

blib/lib/Lim/Component/CLI.pm
Criterion Covered Total %
statement 15 49 30.6
branch 0 18 0.0
condition 0 3 0.0
subroutine 5 13 38.4
pod 7 7 100.0
total 27 90 30.0


line stmt bran cond sub pod time code
1             package Lim::Component::CLI;
2              
3 1     1   8 use common::sense;
  1         3  
  1         8  
4 1     1   52 use Carp;
  1         3  
  1         74  
5              
6 1     1   6 use Log::Log4perl ();
  1         2  
  1         23  
7 1     1   6 use Scalar::Util qw(weaken);
  1         38  
  1         49  
8              
9 1     1   6 use Lim ();
  1         2  
  1         901  
10              
11             =encoding utf8
12              
13             =head1 NAME
14              
15             ...
16              
17             =head1 VERSION
18              
19             See L for version.
20              
21             =cut
22              
23             our $VERSION = $Lim::VERSION;
24              
25             =head1 SYNOPSIS
26              
27             ...
28              
29             =head1 SUBROUTINES/METHODS
30              
31             =head2 new
32              
33             =cut
34              
35             sub new {
36 0     0 1   my $this = shift;
37 0   0       my $class = ref($this) || $this;
38 0           my %args = ( @_ );
39 0           my $self = {
40             logger => Log::Log4perl->get_logger
41             };
42 0           bless $self, $class;
43              
44 0 0         unless (defined $args{cli}) {
45 0           confess __PACKAGE__, ': Missing cli';
46             }
47 0           $self->{cli} = delete $args{cli};
48 0           weaken($self->{cli});
49              
50 0           eval {
51 0           $self->Init(%args);
52             };
53 0 0         if ($@) {
54 0 0         Lim::WARN and $self->{logger}->warn('Unable to initialize module '.$class.': '.$@);
55 0           return;
56             }
57            
58 0 0         Lim::OBJ_DEBUG and $self->{logger}->debug('new ', __PACKAGE__, ' ', $self);
59 0           $self;
60             }
61              
62             sub DESTROY {
63 0     0     my ($self) = @_;
64 0 0         Lim::OBJ_DEBUG and $self->{logger}->debug('destroy ', __PACKAGE__, ' ', $self);
65            
66 0           $self->Destroy;
67             }
68              
69             =head2 Init
70              
71             =cut
72              
73 0     0 1   sub Init {
74             }
75              
76             =head2 Destroy
77              
78             =cut
79              
80 0     0 1   sub Destroy {
81             }
82              
83             =head2 cli
84              
85             =cut
86              
87             sub cli {
88 0     0 1   $_[0]->{cli};
89             }
90              
91             =head2 Prompt
92              
93             =cut
94              
95             sub Prompt {
96 0     0 1   my ($self) = @_;
97            
98 0 0         if (ref($self)) {
99 0           $self = ref($self);
100             }
101 0           $self =~ s/::[^:]+$//o;
102            
103 0           return '/'.lc($self->Name);
104             }
105              
106             =head2 Successful
107              
108             =cut
109              
110             sub Successful {
111 0     0 1   my ($self) = @_;
112            
113 0 0         if (defined $self->{cli}) {
114 0           $self->{cli}->Successful;
115             }
116             }
117              
118             =head2 Error
119              
120             =cut
121              
122             sub Error {
123 0     0 1   my $self = shift;
124            
125 0 0         if (defined $self->{cli}) {
126 0           $self->{cli}->Error(@_);
127             }
128             else {
129 0 0         Lim::ERR and $self->{logger}->error('Command returned error but CLI is gone [', $self, ']');
130             }
131             }
132              
133             =head1 AUTHOR
134              
135             Jerry Lundström, C<< >>
136              
137             =head1 BUGS
138              
139             Please report any bugs or feature requests to L.
140              
141             =head1 SUPPORT
142              
143             You can find documentation for this module with the perldoc command.
144              
145             perldoc Lim
146              
147             You can also look for information at:
148              
149             =over 4
150              
151             =item * Lim issue tracker (report bugs here)
152              
153             L
154              
155             =back
156              
157             =head1 ACKNOWLEDGEMENTS
158              
159             =head1 LICENSE AND COPYRIGHT
160              
161             Copyright 2012-2013 Jerry Lundström.
162              
163             This program is free software; you can redistribute it and/or modify it
164             under the terms of either: the GNU General Public License as published
165             by the Free Software Foundation; or the Artistic License.
166              
167             See http://dev.perl.org/licenses/ for more information.
168              
169              
170             =cut
171              
172             1; # End of Lim::Component::CLI