SlideShare uma empresa Scribd logo
1 de 33
Accessors: 'yes' or 'no'?
Программисты любят аксессоры
Почему?
[object Object],$obj ->foo ( 1 ); print $obj ->foo ; $obj ->{ foo }  =  1 ; print $obj ->{ foo } ;
[object Object],package   MyPackage ; has  'foo'  =>  42 ; 1 ; package   MyPackage ; sub  new  { my  $class =  shift ; my  $self =  bless  { @_ }, $class; $self ->{ foo }  =  42 ; return  $self; } 1 ;
package   MyPackage ; has  'foo'  =>  1 ,  is   =>  'ro' ; has  'bar'  =>  1 ,  isa  =>  'Int' ; 1 ; ,[object Object]
[object Object],package   MyPackage2 ; use base   'MyPackage' ; sub  foo  { my  $self =  shift ; croak( "It's not int!" )  if  @_  and  $_[ 0 ] =~  / ^ + $ / ; $self ->SUPER ::foo(@_); } 1 ;
[object Object]
[object Object],sub  get_foo  { my  $self =  shift ; return  $self ->{ foo } ; } my  $value = $self ->get_foo ;
[object Object],my  $value = $self ->get_foo ; my  $value = $self ->{ foo } ;
[object Object],sub  set_foo  { my  $self =  shift ; die   'Not enough arguments for set_foo'   unless  @_; $self ->{ foo }  =  shift ; return  $self; } $self ->set_foo ( 'bar' );
[object Object],sub  foo  { my  $self =  shift ; return  $self ->{ foo }   unless  @_; die   'Too much arguments'   if  @_ >  1 ; $self ->{ foo }  =  shift ; return  $self; } my  $value = $self ->foo ; $self ->foo ( 'bar' );
Программисты боятся аксессоров
[object Object],my  $value = $self ->foo ; $self ->foo ( 1 ); my  $value = $self ->{ foo } ; $self ->{ foo }  =  1 ;
[object Object],$self ->foo ( 1 );  # accessor $self ->bar ( 1 );  # method
[object Object],sub  bar  { my  $self =  shift ; # ... return   rand ($self ->{ foo } ); }
[object Object]
[object Object]
[object Object]
[object Object]
[object Object]
[object Object]
[object Object]
[object Object]
[object Object],[object Object]
[object Object]
[object Object],use  Mojo::Base::XS -infect;
[object Object]
cpanm Mojo::Base::XS perl -MMojo::Base::XS=-infect
http://github.com/yko/mojo-base-xs
[object Object]
[object Object]
[object Object]

Mais conteúdo relacionado

Destaque

Answer in yes or no for Interview skills
Answer in yes or no for Interview skillsAnswer in yes or no for Interview skills
Answer in yes or no for Interview skillsRosy Ronald
 
Learning
LearningLearning
LearningRayha
 
優しいWAFの作り方
優しいWAFの作り方優しいWAFの作り方
優しいWAFの作り方techmemo
 
How to build a High Performance PSGI/Plack Server
How to build a High Performance PSGI/Plack Server How to build a High Performance PSGI/Plack Server
How to build a High Performance PSGI/Plack Server Masahiro Nagano
 
4th lesson unit 7 questions yes or no past, regular irregular
4th lesson unit 7 questions yes or no past, regular irregular4th lesson unit 7 questions yes or no past, regular irregular
4th lesson unit 7 questions yes or no past, regular irregularinkubo
 

Destaque (7)

Answer in yes or no for Interview skills
Answer in yes or no for Interview skillsAnswer in yes or no for Interview skills
Answer in yes or no for Interview skills
 
Learning
LearningLearning
Learning
 
優しいWAFの作り方
優しいWAFの作り方優しいWAFの作り方
優しいWAFの作り方
 
Yes or no to plastic
Yes or no to plasticYes or no to plastic
Yes or no to plastic
 
China or no
China or noChina or no
China or no
 
How to build a High Performance PSGI/Plack Server
How to build a High Performance PSGI/Plack Server How to build a High Performance PSGI/Plack Server
How to build a High Performance PSGI/Plack Server
 
4th lesson unit 7 questions yes or no past, regular irregular
4th lesson unit 7 questions yes or no past, regular irregular4th lesson unit 7 questions yes or no past, regular irregular
4th lesson unit 7 questions yes or no past, regular irregular
 

Semelhante a Accessors: 'yes' or 'no'

DrupalCamp Kyiv 2011. Views - стандарт вывода списка данных. Расширение Views...
DrupalCamp Kyiv 2011. Views - стандарт вывода списка данных. Расширение Views...DrupalCamp Kyiv 2011. Views - стандарт вывода списка данных. Расширение Views...
DrupalCamp Kyiv 2011. Views - стандарт вывода списка данных. Расширение Views...Viktor Likin
 
ZFConf 2010: jQuery and Dojo Toolkit JavaScript-frameworks Integration with Z...
ZFConf 2010: jQuery and Dojo Toolkit JavaScript-frameworks Integration with Z...ZFConf 2010: jQuery and Dojo Toolkit JavaScript-frameworks Integration with Z...
ZFConf 2010: jQuery and Dojo Toolkit JavaScript-frameworks Integration with Z...ZFConf Conference
 
ZFConf 2010: Zend Framework and Multilingual
ZFConf 2010: Zend Framework and MultilingualZFConf 2010: Zend Framework and Multilingual
ZFConf 2010: Zend Framework and MultilingualZFConf Conference
 
Zen Coding
Zen CodingZen Coding
Zen Coding404fest
 
Js Http Request дмитрий котеров
Js Http Request   дмитрий котеровJs Http Request   дмитрий котеров
Js Http Request дмитрий котеровMedia Gorod
 
Семинар-практикум по Drupal
Семинар-практикум по DrupalСеминар-практикум по Drupal
Семинар-практикум по Drupalit-people
 

Semelhante a Accessors: 'yes' or 'no' (11)

DrupalCamp Kyiv 2011. Views - стандарт вывода списка данных. Расширение Views...
DrupalCamp Kyiv 2011. Views - стандарт вывода списка данных. Расширение Views...DrupalCamp Kyiv 2011. Views - стандарт вывода списка данных. Расширение Views...
DrupalCamp Kyiv 2011. Views - стандарт вывода списка данных. Расширение Views...
 
ZFConf 2010: jQuery and Dojo Toolkit JavaScript-frameworks Integration with Z...
ZFConf 2010: jQuery and Dojo Toolkit JavaScript-frameworks Integration with Z...ZFConf 2010: jQuery and Dojo Toolkit JavaScript-frameworks Integration with Z...
ZFConf 2010: jQuery and Dojo Toolkit JavaScript-frameworks Integration with Z...
 
ZFConf 2010: Zend Framework and Multilingual
ZFConf 2010: Zend Framework and MultilingualZFConf 2010: Zend Framework and Multilingual
ZFConf 2010: Zend Framework and Multilingual
 
DSLs в Perl
DSLs в PerlDSLs в Perl
DSLs в Perl
 
Zen Coding
Zen CodingZen Coding
Zen Coding
 
Perl in practice
Perl in practicePerl in practice
Perl in practice
 
Ruby
RubyRuby
Ruby
 
I Net
I NetI Net
I Net
 
Js Http Request дмитрий котеров
Js Http Request   дмитрий котеровJs Http Request   дмитрий котеров
Js Http Request дмитрий котеров
 
Семинар-практикум по Drupal
Семинар-практикум по DrupalСеминар-практикум по Drupal
Семинар-практикум по Drupal
 
Ci
CiCi
Ci
 

Último (9)

ИСТОЧНИКИ ИННОВАЦИОННОСТИ КИТАЯ (ПО ВЕРСИИ DGAP) | The Sources of China’s Inn...
ИСТОЧНИКИ ИННОВАЦИОННОСТИ КИТАЯ (ПО ВЕРСИИ DGAP) | The Sources of China’s Inn...ИСТОЧНИКИ ИННОВАЦИОННОСТИ КИТАЯ (ПО ВЕРСИИ DGAP) | The Sources of China’s Inn...
ИСТОЧНИКИ ИННОВАЦИОННОСТИ КИТАЯ (ПО ВЕРСИИ DGAP) | The Sources of China’s Inn...
 
CVE. The Fortra's GoAnywhere MFT [RU].pdf
CVE. The Fortra's GoAnywhere MFT [RU].pdfCVE. The Fortra's GoAnywhere MFT [RU].pdf
CVE. The Fortra's GoAnywhere MFT [RU].pdf
 
MS Navigating Incident Response [RU].pdf
MS Navigating Incident Response [RU].pdfMS Navigating Incident Response [RU].pdf
MS Navigating Incident Response [RU].pdf
 
Malware. DCRAT (DARK CRYSTAL RAT) [RU].pdf
Malware. DCRAT (DARK CRYSTAL RAT) [RU].pdfMalware. DCRAT (DARK CRYSTAL RAT) [RU].pdf
Malware. DCRAT (DARK CRYSTAL RAT) [RU].pdf
 
2023 Q4. The Ransomware report. [RU].pdf
2023 Q4. The Ransomware report. [RU].pdf2023 Q4. The Ransomware report. [RU].pdf
2023 Q4. The Ransomware report. [RU].pdf
 
Cyber Defense Doctrine Managing the Risk Full Applied Guide to Organizational...
Cyber Defense Doctrine Managing the Risk Full Applied Guide to Organizational...Cyber Defense Doctrine Managing the Risk Full Applied Guide to Organizational...
Cyber Defense Doctrine Managing the Risk Full Applied Guide to Organizational...
 
СИСТЕМА ОЦЕНКИ УЯЗВИМОСТЕЙ CVSS 4.0 / CVSS v4.0 [RU].pdf
СИСТЕМА ОЦЕНКИ УЯЗВИМОСТЕЙ CVSS 4.0 / CVSS v4.0 [RU].pdfСИСТЕМА ОЦЕНКИ УЯЗВИМОСТЕЙ CVSS 4.0 / CVSS v4.0 [RU].pdf
СИСТЕМА ОЦЕНКИ УЯЗВИМОСТЕЙ CVSS 4.0 / CVSS v4.0 [RU].pdf
 
Cyberprint. Dark Pink Apt Group [RU].pdf
Cyberprint. Dark Pink Apt Group [RU].pdfCyberprint. Dark Pink Apt Group [RU].pdf
Cyberprint. Dark Pink Apt Group [RU].pdf
 
Ransomware_Q3 2023. The report [RU].pdf
Ransomware_Q3 2023.  The report [RU].pdfRansomware_Q3 2023.  The report [RU].pdf
Ransomware_Q3 2023. The report [RU].pdf
 

Accessors: 'yes' or 'no'