line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
##################################################################### |
2
|
|
|
|
|
|
|
# This program is not guaranteed to work at all, and by using this # |
3
|
|
|
|
|
|
|
# program you release the author of any and all liability. # |
4
|
|
|
|
|
|
|
# # |
5
|
|
|
|
|
|
|
# You may use this code as long as you are in compliance with the # |
6
|
|
|
|
|
|
|
# license (see the LICENSE file) and this notice, disclaimer and # |
7
|
|
|
|
|
|
|
# comment box remain intact and unchanged. # |
8
|
|
|
|
|
|
|
# # |
9
|
|
|
|
|
|
|
# Package: Term::RouterCLI # |
10
|
|
|
|
|
|
|
# Class: CommandTree # |
11
|
|
|
|
|
|
|
# Description: Methods for building a Router (Stanford) style CLI # |
12
|
|
|
|
|
|
|
# # |
13
|
|
|
|
|
|
|
# Written by: Bret Jordan (jordan at open1x littledot org) # |
14
|
|
|
|
|
|
|
# Created: 2011-04-09 # |
15
|
|
|
|
|
|
|
##################################################################### |
16
|
|
|
|
|
|
|
# |
17
|
|
|
|
|
|
|
# |
18
|
|
|
|
|
|
|
# |
19
|
|
|
|
|
|
|
# |
20
|
|
|
|
|
|
|
package Term::RouterCLI::CommandTree; |
21
|
|
|
|
|
|
|
|
22
|
4
|
|
|
4
|
|
58
|
use 5.8.8; |
|
4
|
|
|
|
|
14
|
|
|
4
|
|
|
|
|
189
|
|
23
|
4
|
|
|
4
|
|
22
|
use strict; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
200
|
|
24
|
4
|
|
|
4
|
|
25
|
use warnings; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
142
|
|
25
|
|
|
|
|
|
|
|
26
|
4
|
|
|
4
|
|
20
|
use parent qw(Exporter); |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
33
|
|
27
|
|
|
|
|
|
|
our @EXPORT = qw(); |
28
|
|
|
|
|
|
|
our @EXPORT_OK = qw( CreateCommandTree GetCurrentCommandTree GetFullCommandTree AddToCommandTree AuthenticateCommandTree ); |
29
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( 'all' => [ @EXPORT_OK ] ); |
30
|
|
|
|
|
|
|
our $VERSION = '1.00'; |
31
|
|
|
|
|
|
|
$VERSION = eval $VERSION; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
# ---------------------------------------- |
36
|
|
|
|
|
|
|
# Public Functions |
37
|
|
|
|
|
|
|
# ---------------------------------------- |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub CreateCommandTree |
40
|
|
|
|
|
|
|
{ |
41
|
|
|
|
|
|
|
# This method will take in a hash reference and create a command tree |
42
|
|
|
|
|
|
|
# Required: |
43
|
|
|
|
|
|
|
# hash_ref (command tree) |
44
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
45
|
0
|
|
|
|
|
|
my $hCommandTree = shift; |
46
|
|
|
|
|
|
|
|
47
|
0
|
|
|
|
|
|
$self->{'_hFullCommandTree'} = $hCommandTree; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub GetCurrentCommandTree |
51
|
|
|
|
|
|
|
{ |
52
|
|
|
|
|
|
|
# This method will return the a hash ref to the current command tree of all avaliable commands |
53
|
|
|
|
|
|
|
# Return: |
54
|
|
|
|
|
|
|
# hash_ref (command tree) |
55
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
# If there is no _hCommandTreeAtLevel yet, then lets use the _hFullCommandTree as this means |
58
|
|
|
|
|
|
|
# we are just starting at the top |
59
|
0
|
|
0
|
|
|
|
return $self->{'_hCommandTreeAtLevel'} || $self->GetFullCommandTree(); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub GetFullCommandTree |
63
|
|
|
|
|
|
|
{ |
64
|
|
|
|
|
|
|
# This method will return the a hash ref to the full command tree of all avaliable commands |
65
|
|
|
|
|
|
|
# Return: |
66
|
|
|
|
|
|
|
# hash_ref (command tree) |
67
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
# If there is no _hCommandTreeAtLevel yet, then lets use the _hFullCommandTree as this means |
70
|
|
|
|
|
|
|
# we are just starting at the top |
71
|
0
|
|
|
|
|
|
return $self->{'_hFullCommandTree'}; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub AddToCommandTree |
75
|
|
|
|
|
|
|
{ |
76
|
|
|
|
|
|
|
# This method will add commands to the current command tree |
77
|
|
|
|
|
|
|
# Required: |
78
|
|
|
|
|
|
|
# hashref (command tree) |
79
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
80
|
0
|
|
|
|
|
|
my $hAdditionalCommandTree = shift; |
81
|
|
|
|
|
|
|
|
82
|
0
|
|
0
|
|
|
|
my $hCurrentCommandTree = $self->{'_hFullCommandTree'} || {}; |
83
|
0
|
|
|
|
|
|
foreach (keys %$hAdditionalCommandTree) |
84
|
|
|
|
|
|
|
{ |
85
|
0
|
|
|
|
|
|
$hCurrentCommandTree->{$_} = $hAdditionalCommandTree->{$_}; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
return 1; |