line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
2
|
|
|
2
|
|
1223
|
use utf8; |
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
20
|
|
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package Interchange6::Schema::Result::Inventory; |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 NAME |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
Interchange6::Schema::Result::Inventory |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=cut |
10
|
|
|
|
|
|
|
|
11
|
2
|
|
|
2
|
|
92
|
use Interchange6::Schema::Candy; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
15
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 DESCRIPTION |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
The Inventory class is used to store current stock levels for products. |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 ACCESSORS |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head2 sku |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
The SKU of the product. |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
Primary key and foreign constraint on |
24
|
|
|
|
|
|
|
L<Interchange6::Schema::Result::Product/sku> via L</product> relationship. |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=cut |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
primary_column sku => |
29
|
|
|
|
|
|
|
{ data_type => "varchar", size => 64 }; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=head2 quantity |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
This is the quantity currently held in stock. |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
Defaults to 0. |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=cut |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
column quantity => { data_type => "integer", default_value => 0 }; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head1 RELATIONS |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head2 product |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
Type: belongs_to |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
Related object: L<Interchange6::Schema::Result::Product> |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=cut |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
belongs_to |
52
|
|
|
|
|
|
|
product => "Interchange6::Schema::Result::Product", |
53
|
|
|
|
|
|
|
"sku", |
54
|
|
|
|
|
|
|
{ is_deferrable => 1, on_delete => "CASCADE", on_update => "CASCADE" }; |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head1 METHODS |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head2 decrement( $quantity ) |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
Atomically reduce L</quantity> by argument or by 1 if argument is not defined. |
62
|
|
|
|
|
|
|
Returns new value of L</quantity>. |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=cut |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub decrement { |
67
|
2
|
|
|
2
|
1
|
1964
|
my ( $self, $quantity ) = @_; |
68
|
2
|
100
|
|
|
|
11
|
$quantity = 1 unless defined $quantity; |
69
|
2
|
|
|
|
|
17
|
$self->update( { quantity => \[ 'quantity - ?', $quantity ] } ); |
70
|
2
|
|
|
|
|
3247
|
$self->discard_changes; |
71
|
2
|
|
|
|
|
7018
|
return $self->quantity; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=head2 increment( $quantity ) |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
Atomically increase L</quantity> by argument or by 1 if argument is not defined. |
77
|
|
|
|
|
|
|
Returns new value of L</quantity>. |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=cut |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub increment { |
82
|
2
|
|
|
2
|
1
|
2041
|
my ( $self, $quantity ) = @_; |
83
|
2
|
100
|
|
|
|
9
|
$quantity = 1 unless defined $quantity; |
84
|
2
|
|
|
|
|
29
|
$self->update( { quantity => \[ 'quantity + ?', $quantity ] } ); |
85
|
2
|
|
|
|
|
3950
|
$self->discard_changes; |
86
|
2
|
|
|
|
|
7284
|
return $self->quantity; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
1; |