看板 Perl 關於我們 聯絡資訊
我最近想玩perl的OO 不過發現外部存取可以直接存取物件變數 不知道perl是否有啥方是可以避開這樣的問題 ======== code ======== package Foo use strict; use warnings; sub new { my $invocant = shift; my $class = ref($invocant) || $invocant; my $this = { mem1 => "", mem2 => "", }; bless $this, $class; $this->_init(@_); return $this; } ......以下略 ======= code ======= #!/usr/bin/perl my Foo $_foo = new(); $_foo->{'mem1'} = "set"; print $_foo->{'mem1'}."\n"; 我希望讓我的data 封裝&不讓外界任意存取 不知有人有解嗎? 感謝 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.109.183.102
AlanSung:try Moose 02/02 17:32