1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
| #!/usr/bin/env perl
use v5.36;
# --- 国内向けクラス ---
package DomesticPayment;
use v5.36;
use Moo;
has amount => (is => 'ro', required => 1);
sub process ($self) {
my $fee = int($self->amount * 0.03);
my $total = $self->amount + $fee;
say "【国内決済】金額: ¥" . $self->amount . " + 手数料: ¥$fee = 合計: ¥$total";
return $total;
}
package DomesticShipping;
use v5.36;
use Moo;
has address => (is => 'ro', required => 1);
sub ship ($self) {
say "【国内配送】お届け先: " . $self->address;
say " 配送業者: ヤマト運輸";
say " 配送日数: 1-2営業日";
return { carrier => 'yamato', days => 2 };
}
package DomesticNotification;
use v5.36;
use Moo;
has email => (is => 'ro', required => 1);
sub notify ($self, $order_id) {
say "【国内通知】$order_id の注文確認メールを送信";
say " 宛先: " . $self->email;
say " 言語: 日本語";
return 1;
}
# --- 海外向けクラス ---
package GlobalPayment;
use v5.36;
use Moo;
has amount => (is => 'ro', required => 1);
sub process ($self) {
my $fee = int($self->amount * 0.05);
my $total = $self->amount + $fee;
say "【海外決済】Amount: \$" . $self->amount . " + Fee: \$$fee = Total: \$$total";
return $total;
}
package GlobalShipping;
use v5.36;
use Moo;
has address => (is => 'ro', required => 1);
sub ship ($self) {
say "【海外配送】Delivery to: " . $self->address;
say " Carrier: FedEx International";
say " Estimated: 5-10 business days";
return { carrier => 'fedex', days => 10 };
}
package GlobalNotification;
use v5.36;
use Moo;
has email => (is => 'ro', required => 1);
sub notify ($self, $order_id) {
say "【海外通知】Order confirmation for $order_id sent";
say " To: " . $self->email;
say " Language: English";
return 1;
}
# --- メイン処理 ---
package main;
use v5.36;
sub process_order ($order_id, $market, $amount, $address, $email) {
say "=" x 50;
say "注文処理開始: $order_id (市場: $market)";
say "=" x 50;
my ($payment, $shipping, $notification);
# 市場ごとに分岐
if ($market eq 'domestic') {
$payment = DomesticPayment->new(amount => $amount);
$shipping = DomesticShipping->new(address => $address);
$notification = DomesticNotification->new(email => $email);
}
elsif ($market eq 'global') {
$payment = GlobalPayment->new(amount => $amount);
$shipping = GlobalShipping->new(address => $address);
$notification = GlobalNotification->new(email => $email);
}
else {
die "Unknown market: $market";
}
# 処理実行
my $total = $payment->process;
say "";
my $delivery_info = $shipping->ship;
say "";
$notification->notify($order_id);
say "";
say "=" x 50;
say "注文処理完了";
say "=" x 50;
say "";
}
# 国内注文
process_order('ORD-2026-0001', 'domestic', 5000, '東京都渋谷区1-2-3', 'tanaka@example.com');
# 海外注文
process_order('ORD-2026-0002', 'global', 100, '123 Main St, New York, NY', 'john@example.com');
|