| 1 | package Mail::Milter::Authentication::App::Blocker::App::Command::delete; | ||||||||||
| 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 delete a block 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 TOML; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 1 | ▶ | use Text::Table; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | 0 | ▶ | sub abstract { 'Delete a block in a given file' } | ||||||||
|
Subroutine
abstract: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 13 | 0 | ▶ | sub description { 'Delete a block from a given toml file' }; | ||||||||
|
Subroutine
description: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 14 | |||||||||||
| 15 | 0 | ▶ | sub opt_spec { | ||||||||
|
Subroutine
opt_spec: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 16 | return ( | ||||||||||
| 17 | 0 | [ 'file=s', 'Config file to operate on' ], | |||||||||
| 18 | [ 'id=s', 'ID of the block to delete' ], | ||||||||||
| 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 | ▶ | $self->usage_error('Supplied filename does not exist') if ( ! -e $opt->{file} ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 26 | 0 | ▶ | $self->usage_error('Must supply an id') if ( !$opt->{id} ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 27 | 0 | ▶ | $self->usage_error('No args allowed') if @$args; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 28 | } | ||||||||||
| 29 | |||||||||||
| 30 | 0 | ▶ | sub execute($self,$opt,$args) { | ||||||||
|
Subroutine
execute: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 31 | |||||||||||
| 32 | 0 | open ( my $inf, '<', $opt->{file} ); | |||||||||
| 33 | 0 | my $body = do { local $/; <$inf> }; | |||||||||
| 34 | 0 | close $inf; | |||||||||
| 35 | 0 | my ( $data, $error ) = from_toml( $body ); | |||||||||
| 36 | |||||||||||
| 37 | 0 | ▶ | if ( $error ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 38 | 0 | say 'Error parsing file'; | |||||||||
| 39 | 0 | say $error; | |||||||||
| 40 | 0 | exit 1; | |||||||||
| 41 | } | ||||||||||
| 42 | |||||||||||
| 43 | 0 | ▶ | if ( ! exists $data->{$opt->{id}} ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 44 | 0 | say 'The given ID does not exist in that file'; | |||||||||
| 45 | 0 | exit 1; | |||||||||
| 46 | } | ||||||||||
| 47 | |||||||||||
| 48 | 0 | delete $data->{$opt->{id}}; | |||||||||
| 49 | 0 | open my $outf, '>', $opt->{file}; | |||||||||
| 50 | 0 | print $outf to_toml($data); | |||||||||
| 51 | 0 | close $outf; | |||||||||
| 52 | |||||||||||
| 53 | 0 | say 'Block deleted and file saved'; | |||||||||
| 54 | |||||||||||
| 55 | } | ||||||||||
| 56 | |||||||||||
| 57 | 1 | 1; | |||||||||
| 58 | |||||||||||
| 59 | __END__ | ||||||||||