| 1 | package Mail::Milter::Authentication::App::Blocker::App::Command::list; | ||||||||||
| 2 | 1 | ▶ | use 5.20.0; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 1 | ▶ | use Mail::Milter::Authentication::Pragmas; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | # ABSTRACT: Command to list current blocks for a given file | ||||||||||
| 7 | 1 | our $VERSION = '4.20261116'; # VERSION | |||||||||
| 8 | 1 | ▶ | use Mail::Milter::Authentication::App::Blocker::App -command; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 1 | ▶ | use Date::Format; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 1 | ▶ | use TOML; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 1 | ▶ | use Text::Table; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | |||||||||||
| 13 | 0 | ▶ | sub abstract { 'List current blocks in a given file' } | ||||||||
|
Subroutine
abstract: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 14 | 0 | ▶ | sub description { 'Parse a toml file and list the current blocks' } | ||||||||
|
Subroutine
description: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 15 | |||||||||||
| 16 | 0 | ▶ | sub opt_spec { | ||||||||
|
Subroutine
opt_spec: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 17 | return ( | ||||||||||
| 18 | 0 | [ 'file=s@', 'Config files to operate on' ], | |||||||||
| 19 | ); | ||||||||||
| 20 | } | ||||||||||
| 21 | |||||||||||
| 22 | 0 | ▶ | sub validate_args($self,$opt,$args) { | ||||||||
|
Subroutine
validate_args: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||
| 23 | # no args allowed but options! | ||||||||||
| 24 | 0 | ▶ | $self->usage_error('Must supply a filename') if ( !$opt->{file} ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 25 | 0 | foreach my $file ( $opt->{file}->@* ) { | |||||||||
| 26 | 0 | ▶ | $self->usage_error('Supplied filename does not exist') if ( ! -e $file ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 27 | } | ||||||||||
| 28 | 0 | ▶ | $self->usage_error('No args allowed') if @$args; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 29 | } | ||||||||||
| 30 | |||||||||||
| 31 | 0 | ▶ | sub execute($self,$opt,$args) { | ||||||||
|
Subroutine
execute: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||
| 32 | |||||||||||
| 33 | 0 | foreach my $file ( $opt->{file}->@* ) { | |||||||||
| 34 | |||||||||||
| 35 | 0 | say "In file $file"; | |||||||||
| 36 | 0 | say ''; | |||||||||
| 37 | |||||||||||
| 38 | 0 | open ( my $inf, '<', $file ); | |||||||||
| 39 | 0 | my $body = do { local $/; <$inf> }; | |||||||||
| 40 | 0 | close $inf; | |||||||||
| 41 | 0 | my ( $data, $error ) = from_toml( $body ); | |||||||||
| 42 | |||||||||||
| 43 | 0 | ▶ | if ( $error ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 44 | 0 | say 'Error parsing file'; | |||||||||
| 45 | 0 | say $error; | |||||||||
| 46 | 0 | exit 1; | |||||||||
| 47 | } | ||||||||||
| 48 | |||||||||||
| 49 | 0 | my $tb = Text::Table->new( | |||||||||
| 50 | 'Id', | ||||||||||
| 51 | 'Callback', | ||||||||||
| 52 | 'Value', | ||||||||||
| 53 | 'With', | ||||||||||
| 54 | 'Percent', | ||||||||||
| 55 | 'Until', | ||||||||||
| 56 | ); | ||||||||||
| 57 | |||||||||||
| 58 | 0 | foreach my $key ( sort keys $data->%* ) { | |||||||||
| 59 | $tb->add( | ||||||||||
| 60 | $key, | ||||||||||
| 61 | $data->{$key}->{callback}, | ||||||||||
| 62 | $data->{$key}->{value}, | ||||||||||
| 63 | $data->{$key}->{with}, | ||||||||||
| 64 | $data->{$key}->{percent}, | ||||||||||
| 65 | 0 | ▶ | $data->{$key}->{until} ? time2str('%C',$data->{$key}->{until}) : '-', | ||||||||
|
Branch: 1 branch
| |||||||||||
| 66 | ); | ||||||||||
| 67 | } | ||||||||||
| 68 | |||||||||||
| 69 | 0 | print $tb->title; | |||||||||
| 70 | 0 | print $tb->rule('-'); | |||||||||
| 71 | 0 | print $tb->body; | |||||||||
| 72 | 0 | say ''; | |||||||||
| 73 | } | ||||||||||
| 74 | } | ||||||||||
| 75 | |||||||||||
| 76 | 1 | 1; | |||||||||
| 77 | |||||||||||
| 78 | __END__ | ||||||||||