| 1 | package Interchange6::Cart::Cost; | ||||||||||
| 2 | |||||||||||
| 3 | 5 | ▶ | use Interchange6::Types -types; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | 5 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 5 | ▶ | use namespace::clean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | =head1 NAME | ||||||||||
| 9 | |||||||||||
| 10 | Interchange6::Cart::Cost - Cart cost class for Interchange6 Shop Machine | ||||||||||
| 11 | |||||||||||
| 12 | =head1 DESCRIPTION | ||||||||||
| 13 | |||||||||||
| 14 | Cart cost class for L<Interchange6>. | ||||||||||
| 15 | |||||||||||
| 16 | =head1 ATTRIBUTES | ||||||||||
| 17 | |||||||||||
| 18 | =head2 id | ||||||||||
| 19 | |||||||||||
| 20 | Cart id can be used for subclasses, e.g. primary key value for cart or product costs in the database. | ||||||||||
| 21 | |||||||||||
| 22 | =cut | ||||||||||
| 23 | |||||||||||
| 24 | 5 | has id => ( | |||||||||
| 25 | is => 'ro', | ||||||||||
| 26 | isa => Int, | ||||||||||
| 27 | ); | ||||||||||
| 28 | |||||||||||
| 29 | =head2 name | ||||||||||
| 30 | |||||||||||
| 31 | Unique name is required. | ||||||||||
| 32 | |||||||||||
| 33 | =cut | ||||||||||
| 34 | |||||||||||
| 35 | 5 | has name => ( | |||||||||
| 36 | is => 'ro', | ||||||||||
| 37 | isa => NonEmptyStr, | ||||||||||
| 38 | required => 1, | ||||||||||
| 39 | ); | ||||||||||
| 40 | |||||||||||
| 41 | =head2 label | ||||||||||
| 42 | |||||||||||
| 43 | Label for display. Default is same value as label. | ||||||||||
| 44 | |||||||||||
| 45 | =cut | ||||||||||
| 46 | |||||||||||
| 47 | 5 | has label => ( | |||||||||
| 48 | is => 'lazy', | ||||||||||
| 49 | isa => NonEmptyStr, | ||||||||||
| 50 | ); | ||||||||||
| 51 | |||||||||||
| 52 | sub _build_label { | ||||||||||
| 53 | 1 | ▶ | my $self = shift; | ||||||||
|
Subroutine
_build_label: called CC=1 SCAR=0.0
| |||||||||||
| 54 | 1 | return $self->name; | |||||||||
| 55 | }; | ||||||||||
| 56 | |||||||||||
| 57 | =head2 relative | ||||||||||
| 58 | |||||||||||
| 59 | 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. | ||||||||||
| 60 | |||||||||||
| 61 | =cut | ||||||||||
| 62 | |||||||||||
| 63 | 5 | has relative => ( | |||||||||
| 64 | is => 'ro', | ||||||||||
| 65 | isa => Defined & Bool, | ||||||||||
| 66 | default => 0, | ||||||||||
| 67 | ); | ||||||||||
| 68 | |||||||||||
| 69 | =head2 inclusive | ||||||||||
| 70 | |||||||||||
| 71 | 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. | ||||||||||
| 72 | |||||||||||
| 73 | =cut | ||||||||||
| 74 | |||||||||||
| 75 | 5 | has inclusive => ( | |||||||||
| 76 | is => 'ro', | ||||||||||
| 77 | isa => Defined & Bool, | ||||||||||
| 78 | default => 0, | ||||||||||
| 79 | ); | ||||||||||
| 80 | |||||||||||
| 81 | =head2 compound | ||||||||||
| 82 | |||||||||||
| 83 | 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. | ||||||||||
| 84 | |||||||||||
| 85 | Using L</compound> along with L</inclusive> makes no sense and no guarantee is | ||||||||||
| 86 | given as to what the result might be. | ||||||||||
| 87 | |||||||||||
| 88 | =cut | ||||||||||
| 89 | |||||||||||
| 90 | 5 | has compound => ( | |||||||||
| 91 | is => 'ro', | ||||||||||
| 92 | isa => Defined & Bool, | ||||||||||
| 93 | default => 0, | ||||||||||
| 94 | ); | ||||||||||
| 95 | |||||||||||
| 96 | =head2 amount | ||||||||||
| 97 | |||||||||||
| 98 | 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 | ||||||||||
| 99 | |||||||||||
| 100 | =cut | ||||||||||
| 101 | |||||||||||
| 102 | 5 | has amount => ( | |||||||||
| 103 | is => 'ro', | ||||||||||
| 104 | isa => Defined & Num, | ||||||||||
| 105 | required => 1, | ||||||||||
| 106 | ); | ||||||||||
| 107 | |||||||||||
| 108 | =head2 current_amount | ||||||||||
| 109 | |||||||||||
| 110 | 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. | ||||||||||
| 111 | |||||||||||
| 112 | =over | ||||||||||
| 113 | |||||||||||
| 114 | =item Writer: C<set_current_amount> | ||||||||||
| 115 | |||||||||||
| 116 | =back | ||||||||||
| 117 | |||||||||||
| 118 | =cut | ||||||||||
| 119 | |||||||||||
| 120 | has current_amount => ( | ||||||||||
| 121 | is => 'ro', | ||||||||||
| 122 | isa => Num, | ||||||||||
| 123 | 29 | ▶ | coerce => sub { defined $_[0] && sprintf( "%.2f", $_[0] ) }, | ||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||
| 124 | 5 | writer => 'set_current_amount', | |||||||||
| 125 | ); | ||||||||||
| 126 | |||||||||||
| 127 | 5 | 1; | |||||||||