File Coverage

blib/lib/Mail/STS/SSKV.pm
Criterion Covered Total %
statement 17 19 89.4
branch 2 4 50.0
condition n/a
subroutine 3 3 100.0
pod 0 2 0.0
total 22 28 78.5


line stmt bran cond sub pod time code
1             package Mail::STS::SSKV;
2              
3 3     3   4023 use Moose::Role;
  3         16410  
  3         12  
4              
5             our $VERSION = '0.05'; # VERSION
6             # ABSTRACT: role for semicolon-separated key/value pairs
7              
8             requires 'fields';
9              
10             sub new_from_string {
11 4     4 0 180 my ($class, $string) = @_;
12 4         32 my @assignments = split(/\s*;\s*/, $string);
13 4         8 my %kv;
14 4         9 foreach my $assignment (@assignments) {
15 8 50       27 if ($assignment !~ /=/) {
16 0         0 next;
17             }
18 8         21 my ($key, $value) = split(/=/, $assignment, 2);
19 8         25 $kv{$key} = $value;
20             }
21 4 50       13 if (! keys(%kv)) {
22 0         0 return;
23             }
24 4         39 return $class->new(%kv);
25             }
26              
27             sub as_string {
28 4     4 0 1938 my $self = shift;
29             return join(' ',
30 4         7 map { $_."=".$self->$_.";" } grep { defined $self->$_ } @{$self->fields}
  8         207  
  8         226  
  4         159  
31             );
32             }
33              
34             1;
35              
36             __END__
37              
38             =pod
39              
40             =encoding UTF-8
41              
42             =head1 NAME
43              
44             Mail::STS::SSKV - role for semicolon-separated key/value pairs
45              
46             =head1 VERSION
47              
48             version 0.05
49              
50             =head1 AUTHOR
51              
52             Markus Benning <ich@markusbenning.de>
53              
54             =head1 COPYRIGHT AND LICENSE
55              
56             This software is copyright (c) 2018 by Markus Benning <ich@markusbenning.de>.
57              
58             This is free software; you can redistribute it and/or modify it under
59             the same terms as the Perl 5 programming language system itself.
60              
61             =cut