| 1 | package WebService::Affiliate::Role::Voucher; | ||||||||||
| 2 | |||||||||||
| 3 | 4 | ▶ | use Moose::Role; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | 4 | ▶ | use DateTime::Format::ISO8601; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 4 | ▶ | use DateTime::Format::MySQL; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 4 | ▶ | use URI; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | =head1 NAME | ||||||||||
| 10 | |||||||||||
| 11 | WebService::Affiliate::Role::Voucher - Role for basic voucher code attributes. | ||||||||||
| 12 | |||||||||||
| 13 | =cut | ||||||||||
| 14 | |||||||||||
| 15 | =head1 METHODS | ||||||||||
| 16 | |||||||||||
| 17 | =head2 Attributes | ||||||||||
| 18 | |||||||||||
| 19 | =cut | ||||||||||
| 20 | |||||||||||
| 21 | 4 | has code => ( is => 'rw', isa => 'Str', ); | |||||||||
| 22 | 4 | has _starts => ( is => 'rw', isa => 'Str', ); | |||||||||
| 23 | 4 | has starts => ( is => 'rw', isa => 'Maybe[DateTime]', lazy => 1, builder => '_build_starts' ); | |||||||||
| 24 | 4 | has _expires => ( is => 'rw', isa => 'Str', ); | |||||||||
| 25 | 4 | has expires => ( is => 'rw', isa => 'Maybe[DateTime]', lazy => 1, builder => '_build_expires' ); | |||||||||
| 26 | 4 | has description => ( is => 'rw', isa => 'Str', ); | |||||||||
| 27 | 4 | has _url => ( is => 'rw', isa => 'Str', ); | |||||||||
| 28 | 4 | has url => ( is => 'rw', isa => 'Maybe[URI]', lazy => 1, builder => '_build_url' ); | |||||||||
| 29 | 4 | has merchant => ( is => 'rw', isa => 'WebService::Affiliate::Merchant' ); | |||||||||
| 30 | |||||||||||
| 31 | |||||||||||
| 32 | sub _build_starts | ||||||||||
| 33 | 6 | ▶ | { | ||||||||
|
Subroutine
_build_starts: called CC=4 SCAR=13.9
| |||||||||||
| 34 | 6 | my ($self) = @_; | |||||||||
| 35 | |||||||||||
| 36 | 6 | ▶ | return undef if ! $self->_starts; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 37 | |||||||||||
| 38 | 3 | ▶ | return DateTime::Format::MySQL->parse_datetime( $self->_starts ) if $self->_starts =~ /^\d\d\d\d\-\d\d\-\d\d \d\d:\d\d:\d\d$/; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 39 | 1 | ▶ | return DateTime::Format::MySQL->parse_datetime( $self->_starts . ':00' ) if $self->_starts =~ /^\d\d\d\d\-\d\d\-\d\d \d\d:\d\d$/; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 40 | 1 | return DateTime::Format::ISO8601->parse_datetime( $self->_starts ); | |||||||||
| 41 | } | ||||||||||
| 42 | |||||||||||
| 43 | sub _build_expires | ||||||||||
| 44 | 6 | ▶ | { | ||||||||
|
Subroutine
_build_expires: called CC=4 SCAR=23.2
| |||||||||||
| 45 | 6 | my ($self) = @_; | |||||||||
| 46 | |||||||||||
| 47 | 6 | ▶ | return undef if ! $self->_expires; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 48 | |||||||||||
| 49 | 0 | ▶ | return DateTime::Format::MySQL->parse_datetime( $self->_expires ) if $self->_expires =~ /^\d\d\d\d\-\d\d\-\d\d \d\d:\d\d:\d\d$/; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 50 | 0 | ▶ | return DateTime::Format::MySQL->parse_datetime( $self->_expires . ':00' ) if $self->_expires =~ /^\d\d\d\d\-\d\d\-\d\d \d\d:\d\d$/; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 51 | 0 | return DateTime::Format::ISO8601->parse_datetime( $self->_expires ); | |||||||||
| 52 | } | ||||||||||
| 53 | |||||||||||
| 54 | sub _build_url | ||||||||||
| 55 | 6 | ▶ | { | ||||||||
|
Subroutine
_build_url: called CC=2 SCAR=6.9
| |||||||||||
| 56 | 6 | my ($self) = @_; | |||||||||
| 57 | |||||||||||
| 58 | 6 | ▶ | return $self->_url ? URI->new( $self->_url ) : undef; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 59 | } | ||||||||||
| 60 | |||||||||||
| 61 | |||||||||||
| 62 | 4 | 1; | |||||||||