跳轉到內容

Moose 程式設計/語法

來自華夏公益教科書

迄今為止,CPAN 文件的一個重大問題是,它們利用(濫用)了 Moose 是 Class::MOP 應用程式的事實。Class::MOP 是元物件協議構建框架 - 通常從這裡開始就會變得難以理解。Class::MOP 和 Moose 之間存在非常模糊的界限,因為 Moose 是 Class::MOP 的唯一已知應用程式。

本質上,我們在 Class::MOP 中擁有的是一個允許 Moose 簡潔且非 Perl 風格的技巧存檔。Moose 提供了一些這些技巧,但沒有多少糖衣,但通常會將它們糖衣到一個舒適的程度。

在這個 Moose 語法綱要中,我們承諾不再提及 Class::MOP[1]


華夏公益教科書開發階段
稀疏文字 0% 正在開發的文字 25% 成熟的文字 50% 已開發的文字 75% 綜合文字 100%

使用 use Moose; 匯出的關鍵字

  1. has 75% 開發完成
  2. before, after, around 75% 開發完成
  3. blessed
  4. override 0% 開發完成
  5. augment
  6. extends 75% 開發完成
  7. with
  8. meta
  9. 其他函式 - 非汙染完全限定語法 25% 開發完成


使用 'no Moose'

[編輯 | 編輯原始碼]
15:32 <@konobi> less shit to track during runtime
15:33 <@Sartak> EvanCarroll: my $person = Person->new; $person->has("jewelry")
15:33 <@konobi> just _having_ stuff in your namespace will slow the interpreter down
15:33 <@Sartak> if you keep Moose's functions in Person's namespace, that will have weird results
15:33 <@Sartak> if you no Moose, then it's the usual "undefined function" error

^ Class::MOP,最後一次,我發誓。

華夏公益教科書