| 1 | # You may distribute under the terms of either the GNU General Public License | ||||||||||||||||||||||||||||
| 2 | # or the Artistic License (the same terms as Perl itself) | ||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||
| 4 | # (C) Paul Evans, 2015 -- leonerd@leonerd.org.uk | ||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | package App::MatrixTool; | ||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 1 | our $VERSION = '0.06'; | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use Getopt::Long qw( GetOptionsFromArray ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 1 | ▶ | use Future; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 1 | ▶ | use List::Util 1.29 qw( pairmap ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 1 | ▶ | use MIME::Base64 qw( encode_base64 ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | 1 | ▶ | use Module::Pluggable::Object; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | 1 | ▶ | use Module::Runtime qw( use_package_optimistically ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | 1 | ▶ | use Scalar::Util qw( blessed ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | 1 | ▶ | use Socket qw( getnameinfo AF_INET AF_INET6 AF_UNSPEC NI_NUMERICHOST NI_NUMERICSERV ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | 1 | ▶ | use Struct::Dumb qw( readonly_struct ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 1 | ▶ | use Protocol::Matrix::HTTP::Federation; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 1 | my $opt_parser = Getopt::Long::Parser->new( | |||||||||||||||||||||||||||
| 26 | config => [qw( require_order )], | ||||||||||||||||||||||||||||
| 27 | ); | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | =head1 NAME | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | C<App::MatrixTool> - commands to interact with a Matrix home-server | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | Usually this would be used via the F<matrixtool> command | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | $ matrixtool server-key matrix.org | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | Provides the base class and basic level support for commands that interact | ||||||||||||||||||||||||||||
| 42 | with a Matrix home-server. See individual command modules, found under the | ||||||||||||||||||||||||||||
| 43 | C<App::MatrixTool::Command::> namespace, for details on specific commands. | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | =cut | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 1 | readonly_struct ArgSpec => [qw( name print_name optional eatall )]; | |||||||||||||||||||||||||||
| 48 | sub ARGSPECS | ||||||||||||||||||||||||||||
| 49 | { | ||||||||||||||||||||||||||||
| 50 | map { | ||||||||||||||||||||||||||||
| 51 | 0 | ▶ | my $name = $_; | ||||||||||||||||||||||||||
|
Subroutine
ARGSPECS: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 52 | 0 | my $optional = $name =~ s/\?$//; | |||||||||||||||||||||||||||
| 53 | 0 | my $eatall = $name =~ m/\.\.\.$/; | |||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 0 | ( my $print_name = uc $name ) =~ s/_/-/g; | |||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 0 | ▶ | ArgSpec( $name, $print_name, $optional||$eatall, $eatall ) | ||||||||||||||||||||||||||
|
Condition0%0/3
$optional || $eatall
MC/DC0%0/2
$optional || $eatall
$optional
$eatall
Truth table0%0/3
A || B
A= $optionalB= $eatall
| |||||||||||||||||||||||||||||
| 58 | } shift->ARGUMENTS; | ||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 1 | readonly_struct OptSpec => [qw( name print_name shortname getopt description )]; | |||||||||||||||||||||||||||
| 62 | sub OPTSPECS | ||||||||||||||||||||||||||||
| 63 | { | ||||||||||||||||||||||||||||
| 64 | pairmap { | ||||||||||||||||||||||||||||
| 65 | 0 | ▶ | my $getopt = $a; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 0 | $a =~ s/=.*//; | |||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 0 | my $shortname; | |||||||||||||||||||||||||||
| 70 | 0 | ▶ | $a =~ s/^(.)\|// and $shortname = $1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 0 | my $printname = "$a"; # stringify to allocate a new SVtPV - RT95409 | |||||||||||||||||||||||||||
| 73 | 0 | $a =~ s/-/_/g; | |||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 0 | OptSpec( $a, $printname, $shortname, $getopt, $b ) | |||||||||||||||||||||||||||
| 76 | 0 | ▶ | } shift->OPTIONS; | ||||||||||||||||||||||||||
|
Subroutine
OPTSPECS: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | sub new | ||||||||||||||||||||||||||||
| 80 | { | ||||||||||||||||||||||||||||
| 81 | 0 | ▶ | my $class = shift; | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 82 | 0 | return bless { @_ }, $class; | |||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | sub sock_family | ||||||||||||||||||||||||||||
| 86 | { | ||||||||||||||||||||||||||||
| 87 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
sock_family: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 88 | 0 | ▶ | return AF_INET if $self->{inet4}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 89 | 0 | ▶ | return AF_INET6 if $self->{inet6}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | 0 | return AF_UNSPEC; | |||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | sub _pkg_for_command | ||||||||||||||||||||||||||||
| 94 | { | ||||||||||||||||||||||||||||
| 95 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
_pkg_for_command: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 96 | 0 | my ( $cmd ) = @_; | |||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 0 | ▶ | my $class = ref $self || $self; | ||||||||||||||||||||||||||
|
Condition0%0/3
ref $self || $self
MC/DC0%0/2
ref $self || $self
ref $self
$self
Truth table0%0/3
A || B
A= ref $selfB= $self
| |||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 0 | ▶ | my $base = $class eq __PACKAGE__ ? "App::MatrixTool::Command" : $class; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | # Allow hyphens in command names | ||||||||||||||||||||||||||||
| 103 | 0 | $cmd =~ s/-/_/g; | |||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 0 | my $pkg = "${base}::${cmd}"; | |||||||||||||||||||||||||||
| 106 | 0 | use_package_optimistically( $pkg ); | |||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | sub run | ||||||||||||||||||||||||||||
| 110 | { | ||||||||||||||||||||||||||||
| 111 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
run: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 112 | 0 | my @args = @_; | |||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | 0 | my %global_opts; | |||||||||||||||||||||||||||
| 115 | $opt_parser->getoptionsfromarray( \@args, | ||||||||||||||||||||||||||||
| 116 | 'inet4|4' => \$global_opts{inet4}, | ||||||||||||||||||||||||||||
| 117 | 'inet6|6' => \$global_opts{inet6}, | ||||||||||||||||||||||||||||
| 118 | 'print-request' => \$global_opts{print_request}, | ||||||||||||||||||||||||||||
| 119 | 'print-response' => \$global_opts{print_response}, | ||||||||||||||||||||||||||||
| 120 | 0 | ▶ | ) or return 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | 0 | ▶ | my $cmd = @args ? shift @args : "help"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | 0 | my $pkg = $self->_pkg_for_command( $cmd ); | |||||||||||||||||||||||||||
| 125 | 0 | ▶ | $pkg->can( "new" ) or | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 126 | return $self->error( "No such command '$cmd'" ); | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | 0 | my $runner = $pkg->new( %global_opts ); | |||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | 0 | $self->run_command_in_runner( $runner, @args ); | |||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | sub run_command_in_runner | ||||||||||||||||||||||||||||
| 134 | { | ||||||||||||||||||||||||||||
| 135 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
run_command_in_runner: not called CC=11 SCAR=48.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 136 | 0 | my ( $runner, @args ) = @_; | |||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | 0 | my @argvalues; | |||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | 0 | ▶ | if( $runner->can( "OPTIONS" ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 141 | 0 | my %optvalues; | |||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | $opt_parser->getoptionsfromarray( \@args, | ||||||||||||||||||||||||||||
| 144 | 0 | ▶ | map { $_->getopt => \$optvalues{ $_->name } } $runner->OPTSPECS | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 145 | ) or exit 1; | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | 0 | push @argvalues, \%optvalues; | |||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | 0 | my @argspecs = $runner->ARGSPECS; | |||||||||||||||||||||||||||
| 151 | 0 | ▶ | while( @argspecs ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 152 | 0 | my $spec = shift @argspecs; | |||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | 0 | ▶ | if( !@args ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 155 | 0 | ▶ | last if $spec->optional; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | 0 | return $self->error( "Required argument '${\ $spec->print_name }' missing" ); | |||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | 0 | ▶ | if( $spec->eatall ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 161 | 0 | push @argvalues, @args; | |||||||||||||||||||||||||||
| 162 | 0 | @args = (); | |||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||
| 164 | else { | ||||||||||||||||||||||||||||
| 165 | 0 | push @argvalues, shift @args; | |||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||
| 168 | 0 | ▶ | @args and return $self->error( "Found extra arguments" ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | 0 | my $ret = $runner->run( @argvalues ); | |||||||||||||||||||||||||||
| 171 | 0 | ▶ | $ret = $ret->get if blessed $ret and $ret->isa( "Future" ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
builtin::blessed($ret) and $ret->isa("Future")
MC/DC0%0/2
builtin::blessed($ret) and $ret->isa("Future")
builtin::blessed($ret)
$ret->isa("Future")
Truth table0%0/3
A and B
A= builtin::blessed($ret)B= $ret->isa("Future")
| |||||||||||||||||||||||||||||
| 172 | 0 | ▶ | $ret //= 0; | ||||||||||||||||||||||||||
|
Condition0%0/2
$ret //= 0
MC/DC0%0/1
$ret //= 0
$ret
Truth table0%0/2
A
A= $ret
| |||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | 0 | return $ret; | |||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | sub output | ||||||||||||||||||||||||||||
| 178 | { | ||||||||||||||||||||||||||||
| 179 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
output: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 180 | 0 | print @_, "\n"; | |||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | 0 | return 0; | |||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||
| 185 | # Some nicer-formatted outputs for terminals | ||||||||||||||||||||||||||||
| 186 | sub output_ok | ||||||||||||||||||||||||||||
| 187 | { | ||||||||||||||||||||||||||||
| 188 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
output_ok: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 189 | 0 | $self->output( "\e[32m", "[OK]", "\e[m", " ", @_ ); | |||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||
| 192 | sub output_info | ||||||||||||||||||||||||||||
| 193 | { | ||||||||||||||||||||||||||||
| 194 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
output_info: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 195 | 0 | $self->output( "\e[36m", "[INFO]", "\e[m", " ", @_ ); | |||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||
| 198 | sub output_warn | ||||||||||||||||||||||||||||
| 199 | { | ||||||||||||||||||||||||||||
| 200 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
output_warn: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 201 | 0 | $self->output( "\e[33m", "[WARN]", "\e[m", " ", @_ ); | |||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||
| 204 | sub output_fail | ||||||||||||||||||||||||||||
| 205 | { | ||||||||||||||||||||||||||||
| 206 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
output_fail: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 207 | 0 | $self->output( "\e[31m", "[FAIL]", "\e[m", " ", @_ ); | |||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||
| 210 | sub format_binary | ||||||||||||||||||||||||||||
| 211 | { | ||||||||||||||||||||||||||||
| 212 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
format_binary: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 213 | 0 | my ( $bin ) = @_; | |||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||
| 215 | # TODO: A global option to pick the format here | ||||||||||||||||||||||||||||
| 216 | 0 | return "base64::" . do { local $_ = encode_base64( $bin, "" ); s/=+$//; $_ }; | |||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||
| 219 | sub format_hostport | ||||||||||||||||||||||||||||
| 220 | { | ||||||||||||||||||||||||||||
| 221 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
format_hostport: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 222 | 0 | my ( $host, $port ) = @_; | |||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||
| 224 | 0 | ▶ | return "[$host]:$port" if $host =~ m/:/; # IPv6 | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 225 | 0 | return "$host:$port"; | |||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||
| 228 | sub format_addr | ||||||||||||||||||||||||||||
| 229 | { | ||||||||||||||||||||||||||||
| 230 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
format_addr: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 231 | 0 | my ( $addr ) = @_; | |||||||||||||||||||||||||||
| 232 | 0 | my ( $err, $host, $port ) = getnameinfo( $addr, NI_NUMERICHOST|NI_NUMERICSERV ); | |||||||||||||||||||||||||||
| 233 | 0 | ▶ | $err and die $err; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||
| 235 | 0 | return $self->format_hostport( $host, $port ); | |||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||
| 238 | sub error | ||||||||||||||||||||||||||||
| 239 | { | ||||||||||||||||||||||||||||
| 240 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
error: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 241 | 0 | print STDERR @_, "\n"; | |||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||
| 243 | 0 | return 1; | |||||||||||||||||||||||||||
| 244 | } | ||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||
| 246 | ## Command support | ||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||
| 248 | sub federation | ||||||||||||||||||||||||||||
| 249 | { | ||||||||||||||||||||||||||||
| 250 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
federation: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||
| 252 | 0 | ▶ | return $self->{federation} ||= Protocol::Matrix::HTTP::Federation->new; | ||||||||||||||||||||||||||
|
Condition0%0/3
$self->{"federation"} ||= "Protocol::Matrix::HTTP::Federation"->new
MC/DC0%0/2
$self->{"federation"} ||= "Protocol::Matrix::HTTP::Federation"->new
$self->{"federation"}
"Protocol::Matrix::HTTP::Federation"->new
Truth table0%0/3
A ||= B
A= $self->{"federation"}B= "Protocol::Matrix::HTTP::Federation"->new
| |||||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||
| 255 | sub http_client | ||||||||||||||||||||||||||||
| 256 | { | ||||||||||||||||||||||||||||
| 257 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
http_client: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||
| 259 | 0 | ▶ | return $self->{http_client} ||= do { | ||||||||||||||||||||||||||
|
Condition0%0/3
$self->{"http_client"} ||= do {
require App::MatrixTool::HTTPClient;
"App::MatrixTool::HTTPClient"->new("family", $self->sock_family, map({$_, $self->{$_};} "print_request", "print_response"))
}
MC/DC0%0/2
$self->{"http_client"} ||= do {
require App::MatrixTool::HTTPClient;
"App::MatrixTool::HTTPClient"->new("family", $self->sock_family, map({$_, $self->{$_};} "print_request", "print_response"))
}
$self->{"http_client"}
do {
require App::MatrixTool::HTTPClient;
"App::MatrixTool::HTTPClient"->new("family", $self->sock_family, map({$_, $self->{$_};} "print_request", "print_response"))
}
Truth table0%0/3
A ||= B
A= $self->{"http_client"}B= do {
require App::MatrixTool::HTTPClient;
"App::MatrixTool::HTTPClient"->new("family", $self->sock_family, map({$_, $self->{$_};} "print_request", "print_response"))
}
| |||||||||||||||||||||||||||||
| 260 | 0 | require App::MatrixTool::HTTPClient; | |||||||||||||||||||||||||||
| 261 | App::MatrixTool::HTTPClient->new( | ||||||||||||||||||||||||||||
| 262 | family => $self->sock_family, | ||||||||||||||||||||||||||||
| 263 | 0 | map { $_ => $self->{$_} } qw( print_request print_response ), | |||||||||||||||||||||||||||
| 264 | ); | ||||||||||||||||||||||||||||
| 265 | }; | ||||||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||
| 268 | 0 | ▶ | sub server_key_store_path { "$ENV{HOME}/.matrix/server-keys" } | ||||||||||||||||||||||||||
|
Subroutine
server_key_store_path: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||
| 270 | sub server_key_store | ||||||||||||||||||||||||||||
| 271 | { | ||||||||||||||||||||||||||||
| 272 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
server_key_store: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||
| 274 | 0 | ▶ | return $self->{server_key_store} ||= do { | ||||||||||||||||||||||||||
|
Condition0%0/3
$self->{"server_key_store"} ||= do {
require App::MatrixTool::ServerIdStore;
"App::MatrixTool::ServerIdStore"->new("path", $self->server_key_store_path)
}
MC/DC0%0/2
$self->{"server_key_store"} ||= do {
require App::MatrixTool::ServerIdStore;
"App::MatrixTool::ServerIdStore"->new("path", $self->server_key_store_path)
}
$self->{"server_key_store"}
do {
require App::MatrixTool::ServerIdStore;
"App::MatrixTool::ServerIdStore"->new("path", $self->server_key_store_path)
}
Truth table0%0/3
A ||= B
A= $self->{"server_key_store"}B= do {
require App::MatrixTool::ServerIdStore;
"App::MatrixTool::ServerIdStore"->new("path", $self->server_key_store_path)
}
| |||||||||||||||||||||||||||||
| 275 | 0 | require App::MatrixTool::ServerIdStore; | |||||||||||||||||||||||||||
| 276 | 0 | App::MatrixTool::ServerIdStore->new( | |||||||||||||||||||||||||||
| 277 | path => $self->server_key_store_path | ||||||||||||||||||||||||||||
| 278 | ); | ||||||||||||||||||||||||||||
| 279 | }; | ||||||||||||||||||||||||||||
| 280 | } | ||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||
| 282 | 0 | ▶ | sub client_token_store_path { "$ENV{HOME}/.matrix/client-tokens" } | ||||||||||||||||||||||||||
|
Subroutine
client_token_store_path: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||
| 284 | sub client_token_store | ||||||||||||||||||||||||||||
| 285 | { | ||||||||||||||||||||||||||||
| 286 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
client_token_store: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||
| 288 | 0 | ▶ | return $self->{client_token_store} ||= do { | ||||||||||||||||||||||||||
|
Condition0%0/3
$self->{"client_token_store"} ||= do {
require App::MatrixTool::ServerIdStore;
"App::MatrixTool::ServerIdStore"->new("path", $self->client_token_store_path, "encode", "raw")
}
MC/DC0%0/2
$self->{"client_token_store"} ||= do {
require App::MatrixTool::ServerIdStore;
"App::MatrixTool::ServerIdStore"->new("path", $self->client_token_store_path, "encode", "raw")
}
$self->{"client_token_store"}
do {
require App::MatrixTool::ServerIdStore;
"App::MatrixTool::ServerIdStore"->new("path", $self->client_token_store_path, "encode", "raw")
}
Truth table0%0/3
A ||= B
A= $self->{"client_token_store"}B= do {
require App::MatrixTool::ServerIdStore;
"App::MatrixTool::ServerIdStore"->new("path", $self->client_token_store_path, "encode", "raw")
}
| |||||||||||||||||||||||||||||
| 289 | 0 | require App::MatrixTool::ServerIdStore; | |||||||||||||||||||||||||||
| 290 | 0 | App::MatrixTool::ServerIdStore->new( | |||||||||||||||||||||||||||
| 291 | path => $self->client_token_store_path, | ||||||||||||||||||||||||||||
| 292 | encode => "raw", # client tokens are already base64 encoded | ||||||||||||||||||||||||||||
| 293 | ); | ||||||||||||||||||||||||||||
| 294 | }; | ||||||||||||||||||||||||||||
| 295 | } | ||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||
| 297 | ## Builtin commands | ||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||
| 299 | package | ||||||||||||||||||||||||||||
| 300 | App::MatrixTool::Command::help; | ||||||||||||||||||||||||||||
| 301 | 1 | ▶ | use base qw( App::MatrixTool ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||
| 303 | 1 | ▶ | use List::Util qw( max ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||
| 305 | 1 | ▶ | use constant DESCRIPTION => "Display help information about commands"; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 306 | 1 | ▶ | use constant ARGUMENTS => ( "command...?" ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||
| 308 | 1 | ▶ | use Struct::Dumb qw( readonly_struct ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 309 | 1 | readonly_struct CommandSpec => [qw( name description argspecs optspecs package )]; | |||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||
| 311 | sub commands | ||||||||||||||||||||||||||||
| 312 | { | ||||||||||||||||||||||||||||
| 313 | 0 | ▶ | my $mp = Module::Pluggable::Object->new( | ||||||||||||||||||||||||||
|
Subroutine
commands: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 314 | require => 1, | ||||||||||||||||||||||||||||
| 315 | search_path => [ "App::MatrixTool::Command" ], | ||||||||||||||||||||||||||||
| 316 | ); | ||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||
| 318 | 0 | my @commands; | |||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||
| 320 | 0 | foreach my $module ( sort $mp->plugins ) { | |||||||||||||||||||||||||||
| 321 | 0 | ▶ | $module->can( "DESCRIPTION" ) or next; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||
| 323 | 0 | my $cmd = $module; | |||||||||||||||||||||||||||
| 324 | 0 | $cmd =~ s/^App::MatrixTool::Command:://; | |||||||||||||||||||||||||||
| 325 | 0 | $cmd =~ s/_/-/g; | |||||||||||||||||||||||||||
| 326 | 0 | $cmd =~ s/::/ /g; | |||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||
| 328 | 0 | ▶ | push @commands, CommandSpec( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 329 | $cmd, | ||||||||||||||||||||||||||||
| 330 | $module->DESCRIPTION, | ||||||||||||||||||||||||||||
| 331 | [ $module->ARGSPECS ], | ||||||||||||||||||||||||||||
| 332 | $module->can( "OPTIONS" ) ? [ $module->OPTSPECS ] : undef, | ||||||||||||||||||||||||||||
| 333 | $module, | ||||||||||||||||||||||||||||
| 334 | ); | ||||||||||||||||||||||||||||
| 335 | } | ||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||
| 337 | 0 | return @commands; | |||||||||||||||||||||||||||
| 338 | } | ||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||
| 340 | 1 | my $GLOBAL_OPTS = <<'EOF'; | |||||||||||||||||||||||||||
| 341 | Global options: | ||||||||||||||||||||||||||||
| 342 | -4 --inet4 Use only IPv4 | ||||||||||||||||||||||||||||
| 343 | -6 --inet6 Use only IPv6 | ||||||||||||||||||||||||||||
| 344 | --print-request Print sent HTTP requests in full | ||||||||||||||||||||||||||||
| 345 | --print-response Print received HTTP responses in full | ||||||||||||||||||||||||||||
| 346 | EOF | ||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||
| 348 | sub help_summary | ||||||||||||||||||||||||||||
| 349 | { | ||||||||||||||||||||||||||||
| 350 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
help_summary: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||
| 352 | 0 | $self->output( <<'EOF' . $GLOBAL_OPTS ); | |||||||||||||||||||||||||||
| 353 | matrixtool [<global options...>] <command> [<command options...>] | ||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||
| 355 | EOF | ||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||
| 357 | 0 | my @commands = $self->commands; | |||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||
| 359 | 0 | my $namelen = max map { length $_->name } @commands; | |||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||
| 361 | $self->output( "Commands:\n" . | ||||||||||||||||||||||||||||
| 362 | 0 | join "\n", map { sprintf " %-*s %s", $namelen, $_->name, $_->description } @commands | |||||||||||||||||||||||||||
| 363 | ); | ||||||||||||||||||||||||||||
| 364 | } | ||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||
| 366 | sub _argdesc | ||||||||||||||||||||||||||||
| 367 | { | ||||||||||||||||||||||||||||
| 368 | 0 | ▶ | shift; | ||||||||||||||||||||||||||
|
Subroutine
_argdesc: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 369 | 0 | my ( $argspec ) = @_; | |||||||||||||||||||||||||||
| 370 | 0 | my $name = $argspec->print_name; | |||||||||||||||||||||||||||
| 371 | 0 | ▶ | return $argspec->optional ? "[$name]" : $name; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 372 | } | ||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||
| 374 | sub _optdesc | ||||||||||||||||||||||||||||
| 375 | { | ||||||||||||||||||||||||||||
| 376 | 0 | ▶ | my ( $optspec, $namelen ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_optdesc: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||
| 378 | 0 | my $shortname = $optspec->shortname; | |||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||
| 380 | 0 | ▶ | join "", | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 381 | ( defined $shortname ? "-$shortname " : " " ), | ||||||||||||||||||||||||||||
| 382 | sprintf( "--%-*s", $namelen, $optspec->print_name ), | ||||||||||||||||||||||||||||
| 383 | " ", | ||||||||||||||||||||||||||||
| 384 | $optspec->description, | ||||||||||||||||||||||||||||
| 385 | } | ||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||
| 387 | sub help_detailed | ||||||||||||||||||||||||||||
| 388 | { | ||||||||||||||||||||||||||||
| 389 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
help_detailed: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 390 | 0 | my ( $cmd ) = @_; | |||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||
| 392 | 0 | my $pkg = App::MatrixTool->_pkg_for_command( $cmd ); | |||||||||||||||||||||||||||
| 393 | 0 | ▶ | $pkg->can( "new" ) or | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 394 | return $self->error( "No such command '$cmd'" ); | ||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||
| 396 | 0 | my @argspecs = $pkg->ARGSPECS; | |||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||
| 398 | 0 | $self->output( join " ", "matrixtool", | |||||||||||||||||||||||||||
| 399 | "[<global options...>]", | ||||||||||||||||||||||||||||
| 400 | $cmd, | ||||||||||||||||||||||||||||
| 401 | ( map $self->_argdesc($_), @argspecs ), | ||||||||||||||||||||||||||||
| 402 | "[<command options...>]" | ||||||||||||||||||||||||||||
| 403 | ); | ||||||||||||||||||||||||||||
| 404 | 0 | $self->output( $pkg->DESCRIPTION ); | |||||||||||||||||||||||||||
| 405 | 0 | $self->output(); | |||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||
| 407 | 0 | $self->output( $GLOBAL_OPTS ); | |||||||||||||||||||||||||||
| 408 | |||||||||||||||||||||||||||||
| 409 | 0 | ▶ | if( $pkg->can( "OPTIONS" ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 410 | 0 | my @optspecs = $pkg->OPTSPECS; | |||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||
| 412 | 0 | my $namelen = max map { length $_->name } @optspecs; | |||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||
| 414 | 0 | $self->output( "Options:" ); | |||||||||||||||||||||||||||
| 415 | 0 | foreach my $optspec ( sort { $a->name cmp $b->name } @optspecs ) { | |||||||||||||||||||||||||||
| 416 | 0 | $self->output( " " . _optdesc( $optspec, $namelen ) ); | |||||||||||||||||||||||||||
| 417 | } | ||||||||||||||||||||||||||||
| 418 | 0 | $self->output(); | |||||||||||||||||||||||||||
| 419 | } | ||||||||||||||||||||||||||||
| 420 | } | ||||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||
| 422 | sub run | ||||||||||||||||||||||||||||
| 423 | { | ||||||||||||||||||||||||||||
| 424 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
run: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 425 | 0 | my ( @cmd ) = @_; | |||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||
| 427 | 0 | ▶ | if( @cmd ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 428 | 0 | $self->help_detailed( join "::", @cmd ); | |||||||||||||||||||||||||||
| 429 | } | ||||||||||||||||||||||||||||
| 430 | else { | ||||||||||||||||||||||||||||
| 431 | 0 | $self->help_summary; | |||||||||||||||||||||||||||
| 432 | } | ||||||||||||||||||||||||||||
| 433 | } | ||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||
| 435 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 436 | |||||||||||||||||||||||||||||
| 437 | Paul Evans <leonerd@leonerd.org.uk> | ||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||
| 439 | =cut | ||||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||
| 441 | 1 | 0x55AA; | |||||||||||||||||||||||||||