| 1 | # Interchange6::Cart::Cost - Interchange6 cart cost class | ||||||||||
| 2 | |||||||||||
| 3 | package Interchange6::Cart::Cost; | ||||||||||
| 4 | |||||||||||
| 5 | 5 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 5 | ▶ | use Types::Common::String qw/NonEmptyStr/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 5 | ▶ | use Types::Standard qw/Bool Defined Int Num/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 5 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 5 | ▶ | use namespace::clean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | =head1 NAME | ||||||||||
| 13 | |||||||||||
| 14 | Interchange6::Cart::Cost - Cart cost class for Interchange6 Shop Machine | ||||||||||
| 15 | |||||||||||
| 16 | =head1 DESCRIPTION | ||||||||||
| 17 | |||||||||||
| 18 | Cart cost class for L<Interchange6>. | ||||||||||
| 19 | |||||||||||
| 20 | =head1 ATTRIBUTES | ||||||||||
| 21 | |||||||||||
| 22 | =head2 id | ||||||||||
| 23 | |||||||||||
| 24 | Cart id can be used for subclasses, e.g. primary key value for cart or product costs in the database. | ||||||||||
| 25 | |||||||||||
| 26 | =cut | ||||||||||
| 27 | |||||||||||
| 28 | 5 | has id => ( | |||||||||
| 29 | is => 'ro', | ||||||||||
| 30 | isa => Int, | ||||||||||
| 31 | ); | ||||||||||
| 32 | |||||||||||
| 33 | =head2 name | ||||||||||
| 34 | |||||||||||
| 35 | Unique name is required. | ||||||||||
| 36 | |||||||||||
| 37 | =cut | ||||||||||
| 38 | |||||||||||
| 39 | 5 | has name => ( | |||||||||
| 40 | is => 'ro', | ||||||||||
| 41 | isa => NonEmptyStr, | ||||||||||
| 42 | required => 1, | ||||||||||
| 43 | ); | ||||||||||
| 44 | |||||||||||
| 45 | =head2 label | ||||||||||
| 46 | |||||||||||
| 47 | Label for display. Default is same value as label. | ||||||||||
| 48 | |||||||||||
| 49 | =cut | ||||||||||
| 50 | |||||||||||
| 51 | 5 | has label => ( | |||||||||
| 52 | is => 'lazy', | ||||||||||
| 53 | isa => NonEmptyStr, | ||||||||||
| 54 | ); | ||||||||||
| 55 | |||||||||||
| 56 | sub _build_label { | ||||||||||
| 57 | 1 | ▶ | my $self = shift; | ||||||||
|
Subroutine
_build_label: called CC=1 SCAR=0.0
| |||||||||||
| 58 | 1 | return $self->name; | |||||||||
| 59 | }; | ||||||||||
| 60 | |||||||||||
| 61 | =head2 relative | ||||||||||
| 62 | |||||||||||
| 63 | Boolean defaults to 0. If true then L<amount> is relative to L<object subtotal|Intechange6::Role::Cost/subtotal>. If false then L<amount> is an absolute cost. | ||||||||||
| 64 | |||||||||||
| 65 | =cut | ||||||||||
| 66 | |||||||||||
| 67 | 5 | has relative => ( | |||||||||
| 68 | is => 'ro', | ||||||||||
| 69 | isa => Defined & Bool, | ||||||||||
| 70 | default => 0, | ||||||||||
| 71 | ); | ||||||||||
| 72 | |||||||||||
| 73 | =head2 inclusive | ||||||||||
| 74 | |||||||||||
| 75 | Boolean defaults to 0. If true signifies that the cost is already included in the price for example to calculate the tax component for gross prices. | ||||||||||
| 76 | |||||||||||
| 77 | =cut | ||||||||||
| 78 | |||||||||||
| 79 | 5 | has inclusive => ( | |||||||||
| 80 | is => 'ro', | ||||||||||
| 81 | isa => Defined & Bool, | ||||||||||
| 82 | default => 0, | ||||||||||
| 83 | ); | ||||||||||
| 84 | |||||||||||
| 85 | =head2 compound | ||||||||||
| 86 | |||||||||||
| 87 | Boolean defaults to 0. If true signifies that any following costs should be applied to the modified price B<after> this cost has been applied. This might be used for such things as discounts which are applied before taxes are applied to the modified price. | ||||||||||
| 88 | |||||||||||
| 89 | Using L</compound> along with L</inclusive> makes no sense and no guarantee is | ||||||||||
| 90 | given as to what the result might be. | ||||||||||
| 91 | |||||||||||
| 92 | =cut | ||||||||||
| 93 | |||||||||||
| 94 | 5 | has compound => ( | |||||||||
| 95 | is => 'ro', | ||||||||||
| 96 | isa => Defined & Bool, | ||||||||||
| 97 | default => 0, | ||||||||||
| 98 | ); | ||||||||||
| 99 | |||||||||||
| 100 | =head2 amount | ||||||||||
| 101 | |||||||||||
| 102 | Required amount of the cost. This is the absolute cost unless L</relative> is true in which case it is relative to the L<object subtotal|Interchange6::Role::Cost/subtotal>. For example for a tax of 8% amount should be set to 0.08 | ||||||||||
| 103 | |||||||||||
| 104 | =cut | ||||||||||
| 105 | |||||||||||
| 106 | 5 | has amount => ( | |||||||||
| 107 | is => 'ro', | ||||||||||
| 108 | isa => Defined & Num, | ||||||||||
| 109 | required => 1, | ||||||||||
| 110 | ); | ||||||||||
| 111 | |||||||||||
| 112 | =head2 current_amount | ||||||||||
| 113 | |||||||||||
| 114 | Calculated current amount of cost. Unless L</relative> is true this will be the same as L</amount>. If L</relative> is true then this is value is recalulated whenever C<total> is called on the object. | ||||||||||
| 115 | |||||||||||
| 116 | =over | ||||||||||
| 117 | |||||||||||
| 118 | =item Writer: C<set_current_amount> | ||||||||||
| 119 | |||||||||||
| 120 | =back | ||||||||||
| 121 | |||||||||||
| 122 | =cut | ||||||||||
| 123 | |||||||||||
| 124 | has current_amount => ( | ||||||||||
| 125 | is => 'ro', | ||||||||||
| 126 | isa => Num, | ||||||||||
| 127 | 29 | ▶ | coerce => sub { defined $_[0] && sprintf( "%.2f", $_[0] ) }, | ||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||
| 128 | 5 | writer => 'set_current_amount', | |||||||||
| 129 | ); | ||||||||||
| 130 | |||||||||||
| 131 | 5 | 1; | |||||||||