Skip to content

Commit 7562ff1

Browse files
waterkiptimlegge
authored andcommitted
Make use of builders instead of using BUILDARGS
Signed-off-by: Wesley Schwengle <[email protected]>
1 parent d46073c commit 7562ff1

File tree

3 files changed

+51
-30
lines changed

3 files changed

+51
-30
lines changed

Makefile.PL

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ my %WriteMakefileArgs = (
4949
"XML::XPath" => 0,
5050
"base" => 0,
5151
"constant" => 0,
52+
"namespace::autoclean" => 0,
5253
"strict" => 0,
5354
"vars" => 0,
5455
"warnings" => 0
@@ -66,8 +67,7 @@ my %WriteMakefileArgs = (
6667
"Test::Pod" => "1.14",
6768
"Test::Pod::Coverage" => "1.04",
6869
"XML::LibXML" => 0,
69-
"XML::LibXML::XPathContext" => 0,
70-
"namespace::autoclean" => 0
70+
"XML::LibXML::XPathContext" => 0
7171
},
7272
"VERSION" => "0.26",
7373
"test" => {

cpanfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ requires "XML::Writer" => "0";
3333
requires "XML::XPath" => "0";
3434
requires "base" => "0";
3535
requires "constant" => "0";
36+
requires "namespace::autoclean" => "0";
3637
requires "perl" => "5.008_001";
3738
requires "strict" => "0";
3839
requires "vars" => "0";
@@ -52,7 +53,6 @@ on 'test' => sub {
5253
requires "Test::Pod::Coverage" => "1.04";
5354
requires "XML::LibXML" => "0";
5455
requires "XML::LibXML::XPathContext" => "0";
55-
requires "namespace::autoclean" => "0";
5656
};
5757

5858
on 'configure' => sub {

lib/Net/SAML2/Role/ProtocolMessage.pm

Lines changed: 48 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
package Net::SAML2::Role::ProtocolMessage;
2+
23
use Moose::Role;
3-
use MooseX::Types::Moose qw/ Str /;
4-
use MooseX::Types::URI qw/ Uri /;
5-
use DateTime::Format::XSD;
6-
use XML::Generator;
7-
use Net::SAML2::Util qw(generate_id);
84

9-
=head1 NAME
5+
# ABSTRACT: Common behaviour for Protocol messages
106

11-
Net::SAML2::Role::ProtocolMessage - common behaviour for Protocol messages
7+
use namespace::autoclean;
8+
9+
use DateTime;
10+
use MooseX::Types::URI qw/ Uri /;
11+
use Net::SAML2::Util qw(generate_id);
1212

1313
=head1 DESCRIPTION
1414
@@ -19,27 +19,48 @@ implementation.
1919
2020
=cut
2121

22-
has 'id' => (isa => Str, is => 'ro', required => 1);
23-
has 'issue_instant' => (isa => Str, is => 'ro', required => 1);
24-
has 'issuer' => (isa => Uri, is => 'rw', required => 1, coerce => 1);
25-
has 'issuer_namequalifier' => (isa => Str, is => 'rw', required => 0);
26-
has 'issuer_format' => (isa => Str, is => 'rw', required => 0);
27-
has 'destination' => (isa => Uri, is => 'rw', required => 0, coerce => 1);
28-
29-
around 'BUILDARGS' => sub {
30-
my $orig = shift;
31-
my $class = shift;
32-
my %args = @_;
33-
34-
# random ID for this message
35-
$args{id} ||= generate_id();
36-
37-
# IssueInstant in UTC
38-
my $dt = DateTime->now( time_zone => 'UTC' );
39-
$args{issue_instant} ||= $dt->strftime('%FT%TZ');
22+
has id => (
23+
isa => 'Str',
24+
is => 'ro',
25+
builder => "_build_id"
26+
);
27+
28+
has issue_instant => (
29+
isa => 'Str',
30+
is => 'ro',
31+
builder => '_build_issue_instant',
32+
);
33+
34+
has issuer => (
35+
isa => Uri,
36+
is => 'rw',
37+
required => 1,
38+
coerce => 1,
39+
);
40+
41+
has issuer_namequalifier => (
42+
isa => 'Str',
43+
is => 'rw'
44+
);
45+
46+
has issuer_format => (
47+
isa => 'Str',
48+
is => 'rw'
49+
);
50+
51+
has destination => (
52+
isa => Uri,
53+
is => 'rw',
54+
coerce => 1
55+
);
56+
57+
sub _build_issue_instant {
58+
return DateTime->now(time_zone => 'UTC')->strftime('%FT%TZ');
59+
}
4060

41-
return \%args;
42-
};
61+
sub _build_id {
62+
return generate_id();
63+
}
4364

4465
=head1 CONSTRUCTOR ARGUMENTS
4566

0 commit comments

Comments
 (0)