File Coverage

lib/Wireguard/WGmeta/Cli/Router.pm
Criterion Covered Total %
statement 52 65 80.0
branch 7 16 43.7
condition n/a
subroutine 13 13 100.0
pod 1 1 100.0
total 73 95 76.8


line stmt bran cond sub pod time code
1             =head1 NAME
2              
3             Cli::Router - Routes commands to their implementation
4              
5             =head1 DESCRIPTION
6              
7             If you want to "register" a new command, do it here. For more information about how an actual implementation should look like
8             please refer to L.
9              
10             =head1 METHODS
11              
12             =cut
13              
14             package Wireguard::WGmeta::Cli::Router;
15 1     1   78064 use strict;
  1         2  
  1         32  
16 1     1   6 use warnings FATAL => 'all';
  1         2  
  1         34  
17 1     1   6 use experimental 'signatures';
  1         2  
  1         9  
18 1     1   625 use Wireguard::WGmeta::Cli::Commands::Show;
  1         3  
  1         31  
19 1     1   470 use Wireguard::WGmeta::Cli::Commands::Set;
  1         3  
  1         36  
20 1     1   458 use Wireguard::WGmeta::Cli::Commands::Help;
  1         3  
  1         28  
21 1     1   452 use Wireguard::WGmeta::Cli::Commands::Enable;
  1         3  
  1         30  
22 1     1   444 use Wireguard::WGmeta::Cli::Commands::Disable;
  1         7  
  1         28  
23 1     1   448 use Wireguard::WGmeta::Cli::Commands::Apply;
  1         3  
  1         28  
24 1     1   516 use Wireguard::WGmeta::Cli::Commands::Add;
  1         3  
  1         29  
25 1     1   438 use Wireguard::WGmeta::Cli::Commands::Remove;
  1         13  
  1         30  
26              
27 1     1   6 use base 'Exporter';
  1         5  
  1         488  
28             our @EXPORT = qw(route_command);
29              
30             our $VERSION = "0.3.4";
31              
32             =head2 route_command($ref_list_input_args)
33              
34             Routes the cmd (first argument of C<@ARGV>) to their implementation. The case of the commands to not matter.
35             Any unknown command is forwarded to L.
36              
37             To add a new command add this to the C block:
38              
39             /^your_cmd$/ && do {
40             Wireguard::WGmeta::Cli::Commands::YourCmd->new(@cmd_args)->entry_point();
41             last;
42             };
43              
44              
45             B
46              
47             =over 1
48              
49             =item
50              
51             C<$ref_list_input_args> Reference to C<@ARGV>)
52              
53             =back
54              
55             B
56              
57             None
58              
59             =cut
60 5     5 1 1681 sub route_command($ref_list_input_args) {
  5         11  
  5         7  
61 5         15 my ($cmd,@cmd_args) = @$ref_list_input_args;
62 5 50       16 if (!defined $cmd){
63 0         0 Wireguard::WGmeta::Cli::Commands::Help->new->entry_point;
64             }
65 5         12 for ($cmd) {
66 5 50       16 /^show$/ && do {
67 0         0 Wireguard::WGmeta::Cli::Commands::Show->new(@cmd_args)->entry_point();
68 0         0 last;
69             };
70 5 100       21 /^set$/ && do {
71 3         26 Wireguard::WGmeta::Cli::Commands::Set->new(@cmd_args)->entry_point();
72 2         44 last;
73             };
74 2 100       9 /^enable$/ && do {
75 1         13 Wireguard::WGmeta::Cli::Commands::Enable->new(@cmd_args)->entry_point();
76 1         26 last;
77             };
78 1 50       7 /^disable$/ && do {
79 1         15 Wireguard::WGmeta::Cli::Commands::Disable->new(@cmd_args)->entry_point();
80 1         26 last;
81             };
82 0 0         /^addpeer$/ && do {
83 0           Wireguard::WGmeta::Cli::Commands::Add->new(@cmd_args)->entry_point();
84 0           last;
85             };
86 0 0         /^removepeer$/ && do {
87 0           Wireguard::WGmeta::Cli::Commands::Remove->new(@cmd_args)->entry_point();
88 0           last;
89             };
90 0 0         /^apply$/ && do {
91 0           Wireguard::WGmeta::Cli::Commands::Apply->new(@cmd_args)->entry_point();
92 0           last;
93             };
94 0           Wireguard::WGmeta::Cli::Commands::Help->new->entry_point;
95             }
96             }
97              
98             1;