File Coverage

blib/lib/WebService/ValidSign/Object/DocumentPackage.pm
Criterion Covered Total %
statement 23 36 63.8
branch 3 10 30.0
condition n/a
subroutine 7 9 77.7
pod n/a
total 33 55 60.0


line stmt bran cond sub pod time code
1             ## Please see file perltidy.ERR
2             package WebService::ValidSign::Object::DocumentPackage;
3             our $VERSION = '0.003';
4 2     2   1873 use Moo;
  2         6  
  2         12  
5              
6             extends 'WebService::ValidSign::Object';
7              
8 2     2   730 use Types::Standard qw(Str Bool ArrayRef HashRef);
  2         5  
  2         20  
9 2     2   2974 use WebService::ValidSign::Object::Ceremony;
  2         54  
  2         72  
10              
11             # TODO:
12             # Add coerce sender
13             # Add coerce settings
14             # Add coerce roles
15             #
16 2     2   18 use WebService::ValidSign::Types qw();
  2         4  
  2         1029  
17              
18             # ABSTRACT: A ValidSign DocumentPackage object
19              
20             has '+type' => (default => "PACKAGE");
21              
22             has name => (
23             is => 'ro',
24             required => 1,
25             );
26              
27             has language => (
28             is => 'rw',
29             isa => Str,
30             default => 'en',
31             );
32              
33             has email_message => (
34             is => 'rw',
35             isa => Str,
36             );
37              
38             has auto_complete => (
39             is => 'rw',
40             isa => Bool,
41             default => 1,
42             );
43              
44             has description => (
45             is => 'rw',
46             isa => Str,
47             );
48              
49             has sender => (
50             is => 'rw',
51             predicate => 'has_sender',
52             # coerce => 1
53             );
54              
55             has settings => (
56             is => 'rw',
57             builder => 1
58             );
59              
60             has visibility => (
61             is => 'rw',
62             isa => Str,
63             default => 'ACCOUNT',
64             );
65              
66             has roles => (
67             is => 'rw',
68             default => sub { [] },
69             isa => ArrayRef,
70             traits => ["Array"],
71             predicate => 'has_roles',
72              
73             #handles => {
74             # add_signer => 'push',
75             # count_signer => 'elements',
76             # delete_signer => 'delete',
77             #},
78             );
79              
80             has documents => (
81             is => 'rw',
82             lazy => 1,
83             isa => ArrayRef,
84             predicate => 'has_documents',
85             default => sub { [] },
86             );
87              
88             sub _build_settings {
89 4     4   114 my $self = shift;
90 4         58 return { ceremony => WebService::ValidSign::Object::Ceremony->new() };
91             }
92              
93             sub add_document {
94 1     1   123 my ($self, $document) = @_;
95 1 50       5 if ($self->count_documents) {
96 0         0 croak("Current implementation only supports one document!");
97             }
98              
99 1         3 push(@{$self->documents}, $document);
  1         21  
100 1         27 return 1;
101             };
102              
103             sub count_documents {
104 4     4   1725 my $self = shift;
105 4 100       20 return 0 unless $self->has_documents;
106 3         7 return scalar @{$self->documents};
  3         73  
107             }
108              
109              
110             sub add_role {
111 0     0     my $self = shift;
112 0           my $role_name = shift;
113 0           my $signer = shift;
114 0 0         if ($self->count_roles) {
115 0           croak("Current implementation only supports one signer!");
116             }
117              
118 0 0         if (!$signer->can("as_signer")) {
119 0           croak("You need to implement as_signer");
120             }
121              
122             #push(@{$self->signers}, $signer->as_signer);
123 0           return 1;
124             };
125              
126             sub count_roles {
127 0     0     my $self = shift;
128 0 0         return 0 unless $self->has_roles;
129 0           return scalar @{$self->roles};
  0            
130             }
131              
132             __PACKAGE__->meta->make_immutable;
133              
134             __END__
135              
136             =pod
137              
138             =encoding UTF-8
139              
140             =head1 NAME
141              
142             WebService::ValidSign::Object::DocumentPackage - A ValidSign DocumentPackage object
143              
144             =head1 VERSION
145              
146             version 0.003
147              
148             =head1 AUTHOR
149              
150             Wesley Schwengle <waterkip@cpan.org>
151              
152             =head1 COPYRIGHT AND LICENSE
153              
154             This software is Copyright (c) 2019 by Wesley Schwengle.
155              
156             This is free software, licensed under:
157              
158             The (three-clause) BSD License
159              
160             =cut