मैं अभी Moose का उपयोग शुरू कर रहा हूं।आप मूस में उपप्रकार कैसे बनाते हैं?
मैं एक साधारण अधिसूचना वस्तु बना रहा हूं और इनपुट जांचना चाहता हूं कि 'ईमेल' प्रकार का है। (अब सरल रेगेक्स मैच के लिए अनदेखा करें)।
प्रलेखन मेरा मानना है कि यह निम्न कोड की तरह दिखना चाहिए से:
# --- contents of message.pl --- #
package Message;
use Moose;
subtype 'Email' => as 'Str' => where { /.*@.*/ } ;
has 'subject' => (isa => 'Str', is => 'rw',);
has 'to' => (isa => 'Email', is => 'rw',);
no Moose; 1;
#############################
package main;
my $msg = Message->new(
subject => 'Hello, World!',
to => '[email protected]'
);
print $msg->{to} . "\n";
लेकिन मैं निम्नलिखित त्रुटियाँ मिलती है:
String found where operator expected at message.pl line 5, near "subtype 'Email'" (Do you need to predeclare subtype?) String found where operator expected at message.pl line 5, near "as 'Str'" (Do you need to predeclare as?) syntax error at message.pl line 5, near "subtype 'Email'" BEGIN not safe after errors--compilation aborted at message.pl line 10.
किसी को भी पता है मूस में एक कस्टम ईमेल उप प्रकार बनाने के लिए कैसे?
मूस-संस्करण: 0.72 पर्ल संस्करण: 5.10.0, मंच: लिनक्स ubuntu 8.10
ईमेल :: मेल सत्यापन के लिए मान्य ++ # regexes बुराई – brunov
@bruno है v - और ईमेल :: मान्य :: आरएफसी 822 सत्यापन के लिए रेगेक्स का उपयोग करता है। – converter42