SlideShare una empresa de Scribd logo
1 de 22
Introduction to Object Oriented Programming in Perl with Moose.




  Introduction to Object
  Oriented Programming
       with Moose
What is an Object?

• Holds information about it’s self
• Does stuff (functions)
• defined by a class (not an object)
OO in Perl?

• DateTime
• WWW::Mechanize
• DBI
• IO::Handle
Often created with
         new

• my $mech = WWW::Mechanize->new
• my $dt = DateTime->new(year => 2000,
  month => ...);
But not always


• my $dt = DateTime->now(time_zone =>
  ‘America/Chicago’);
Holds information

• my $mech = WWW::Mechanize->new
• $mech->get($url)
• my $content = $mech->content()
Not an object.


• use Cwd;
• my $dir = getcwd();
Some times globals point the need for an
                  object
#!/usr/bin/env perl
use strict;
use warnings;
use WWW::Mechanize;

my $base = ‘http://www.google.com/search?q=’;
my $mech = $mech->new;

print query(“perl”)
print query(“moose”)

sub query {
  my $query = shift;
  $mech->get($url . $query);
  return $mech->content;
}
Becomes....
package SearchEngine;
use Moose;
use WWW::Mechanize;

has ‘url_base’ => (isa => Str, is => ‘rw’,
               default => ‘http://www.google.com/search?q=’);
has ‘mech’ => (isa => Object, is => ‘ro’,
               default => sub {WWW::Mechanize->new});

sub query {
  my $self = shift;
  my $query = shift;

 $self->mech->get($self->url_base . $query);
 return $self->mech->content;
}
1;
Now I can query away

use SearchEngine;

my $google = SearchEngine->new;
my $alta = SearchEngine->new(url_base =>
‘http://www.altavista.com/web/results?q=’);

print $google->query(‘perl’);
print $alta->query(‘perl’);

print $google->query(‘Moose’);
print $alta->query(‘Moose’);
Change engines after new



use SearchEngine;

my $search = SearchEngine->new; # defaults to google
$search->url_base(‘http://www.altavista.com/web/results?q=’);

print $search->query(‘perl’);
Moose out of the box

• Type constraints (                           )
                  http://tinyurl.com/moose-types


• use strict;
• use warnings
• don’t have to define new
• Delegation
package SearchEngine;
                          Delegation
use Moose;
use WWW::Mechanize;

has ‘url_base’ => (isa => Str, is => ‘rw’,
               default => ‘http://www.google.com/search?q=’);
has ‘mech’ => (isa => Object, is => ‘ro’,
               default => sub {WWW::Mechanize->new},
               handles => { ‘content’ => ‘content’ }
               handles => { ‘get’ => ‘get’ } );

sub query {
  my $self = shift;
  my $query = shift;

 #$self->mech->get($self->url_base . $query);
 $self->get($self->url_base . $query);

 #return $self->mech->content;
 return $self->content;
}
1;
Why Moose?


• See slide 25 - Intro to Moose
Why Moose
•   Moose means less code

    •   (less code == less bugs)

•   Less tests

    •   (why test what moose already does)

•   over 6000 unit tests

•   0.24 seconds load time

•   ~ 3mb for perl+moose
No Moose

•no Moose at the end of a package is a
  best practice
• Just do it
Immutability

  Stevan's Incantation of Fleet-
  Footedness
package Person;
use Moose;


__PACKAGE__->meta->make_immutable;
What make_immutable does



  Magic
• Uses eval to "inline" a constructor
• Memoizes a lot of meta-information
• Makes loading your class slower
• Makes object creation much faster
no immutable Moose;
package SearchEngine;
use Moose;
use WWW::Mechanize;

has ‘url_base’ => (isa => Str, is => ‘rw’,
               default => ‘http://www.google.com/search?q=’);
has ‘mech’ => (isa => Object, is => ‘ro’,
               default => sub {WWW::Mechanize->new},
               handles => { ‘content’ => ‘content’ }
               handles => { ‘get’ => ‘get’ } );

sub query {
  my $self = shift;
  my $query = shift;

 #$self->mech->get($self->url_base . $query);
 $self->get($self->url_base . $query);

 #return $self->mech->content;
 return $self->content;
}
__PACKAGE__->meta->make_immutable
no Moose;
1;
Moose is cool for tests!
# no_net.t

package pseudomech;
sub new{return bless {}}
sub get{
  my $self = shift;
  $self->{query} = shift;
}
sub content {
  return shift->{query} . “ response”;
}

package main;
use Test::More tests => 2;
use SearchEngine;

my $google = SearchEngine->new(mech => pseudomech->new);

is($google->query(‘perl’), ‘perl response’);
is($google->query(‘Moose’), ‘Moose response’);

exit;
Roles

• Usually what you want when you try to do
  inheritance
• lets 1 class take on the features of multiple
  packages.
More Reading
• Moose Cookbook (heavy on the
  inheritance)
 • http://search.cpan.org/dist/Moose/lib/
    Moose/Cookbook.pod
• Moose Website
 • http://moose.perl.org

Más contenido relacionado

La actualidad más candente

Moose workshop
Moose workshopMoose workshop
Moose workshopYnon Perek
 
To infinity and beyond
To infinity and beyondTo infinity and beyond
To infinity and beyondclintongormley
 
WordPress Cuztom Helper
WordPress Cuztom HelperWordPress Cuztom Helper
WordPress Cuztom Helperslicejack
 
The effective use of Django ORM
The effective use of Django ORMThe effective use of Django ORM
The effective use of Django ORMYaroslav Muravskyi
 
Django - 次の一歩 gumiStudy#3
Django - 次の一歩 gumiStudy#3Django - 次の一歩 gumiStudy#3
Django - 次の一歩 gumiStudy#3makoto tsuyuki
 
Doctrine MongoDB ODM (PDXPHP)
Doctrine MongoDB ODM (PDXPHP)Doctrine MongoDB ODM (PDXPHP)
Doctrine MongoDB ODM (PDXPHP)Kris Wallsmith
 
Keeping It Small with Slim
Keeping It Small with SlimKeeping It Small with Slim
Keeping It Small with SlimRaven Tools
 
The Best (and Worst) of Django
The Best (and Worst) of DjangoThe Best (and Worst) of Django
The Best (and Worst) of DjangoJacob Kaplan-Moss
 
Moving from Django Apps to Services
Moving from Django Apps to ServicesMoving from Django Apps to Services
Moving from Django Apps to ServicesCraig Kerstiens
 
Introducing Assetic (NYPHP)
Introducing Assetic (NYPHP)Introducing Assetic (NYPHP)
Introducing Assetic (NYPHP)Kris Wallsmith
 
Advanced symfony Techniques
Advanced symfony TechniquesAdvanced symfony Techniques
Advanced symfony TechniquesKris Wallsmith
 
From mysql to MongoDB(MongoDB2011北京交流会)
From mysql to MongoDB(MongoDB2011北京交流会)From mysql to MongoDB(MongoDB2011北京交流会)
From mysql to MongoDB(MongoDB2011北京交流会)Night Sailer
 
Simple Photo Processing and Web Display with Perl
Simple Photo Processing and Web Display with PerlSimple Photo Processing and Web Display with Perl
Simple Photo Processing and Web Display with PerlKent Cowgill
 
Going crazy with Node.JS and CakePHP
Going crazy with Node.JS and CakePHPGoing crazy with Node.JS and CakePHP
Going crazy with Node.JS and CakePHPMariano Iglesias
 
Puppet Camp DC 2015: Stop Writing Puppet Modules: A Guide to Best Practices i...
Puppet Camp DC 2015: Stop Writing Puppet Modules: A Guide to Best Practices i...Puppet Camp DC 2015: Stop Writing Puppet Modules: A Guide to Best Practices i...
Puppet Camp DC 2015: Stop Writing Puppet Modules: A Guide to Best Practices i...Puppet
 
WordPress London 16 May 2012 - You don’t know query
WordPress London 16 May 2012 - You don’t know queryWordPress London 16 May 2012 - You don’t know query
WordPress London 16 May 2012 - You don’t know queryl3rady
 

La actualidad más candente (19)

Moose workshop
Moose workshopMoose workshop
Moose workshop
 
To infinity and beyond
To infinity and beyondTo infinity and beyond
To infinity and beyond
 
WordPress Cuztom Helper
WordPress Cuztom HelperWordPress Cuztom Helper
WordPress Cuztom Helper
 
The effective use of Django ORM
The effective use of Django ORMThe effective use of Django ORM
The effective use of Django ORM
 
Django - 次の一歩 gumiStudy#3
Django - 次の一歩 gumiStudy#3Django - 次の一歩 gumiStudy#3
Django - 次の一歩 gumiStudy#3
 
Doctrine MongoDB ODM (PDXPHP)
Doctrine MongoDB ODM (PDXPHP)Doctrine MongoDB ODM (PDXPHP)
Doctrine MongoDB ODM (PDXPHP)
 
Nubilus Perl
Nubilus PerlNubilus Perl
Nubilus Perl
 
Perl Web Client
Perl Web ClientPerl Web Client
Perl Web Client
 
Keeping It Small with Slim
Keeping It Small with SlimKeeping It Small with Slim
Keeping It Small with Slim
 
The Best (and Worst) of Django
The Best (and Worst) of DjangoThe Best (and Worst) of Django
The Best (and Worst) of Django
 
Moving from Django Apps to Services
Moving from Django Apps to ServicesMoving from Django Apps to Services
Moving from Django Apps to Services
 
Introducing Assetic (NYPHP)
Introducing Assetic (NYPHP)Introducing Assetic (NYPHP)
Introducing Assetic (NYPHP)
 
Advanced symfony Techniques
Advanced symfony TechniquesAdvanced symfony Techniques
Advanced symfony Techniques
 
From mysql to MongoDB(MongoDB2011北京交流会)
From mysql to MongoDB(MongoDB2011北京交流会)From mysql to MongoDB(MongoDB2011北京交流会)
From mysql to MongoDB(MongoDB2011北京交流会)
 
Simple Photo Processing and Web Display with Perl
Simple Photo Processing and Web Display with PerlSimple Photo Processing and Web Display with Perl
Simple Photo Processing and Web Display with Perl
 
Going crazy with Node.JS and CakePHP
Going crazy with Node.JS and CakePHPGoing crazy with Node.JS and CakePHP
Going crazy with Node.JS and CakePHP
 
Puppet Camp DC 2015: Stop Writing Puppet Modules: A Guide to Best Practices i...
Puppet Camp DC 2015: Stop Writing Puppet Modules: A Guide to Best Practices i...Puppet Camp DC 2015: Stop Writing Puppet Modules: A Guide to Best Practices i...
Puppet Camp DC 2015: Stop Writing Puppet Modules: A Guide to Best Practices i...
 
Mocking Demystified
Mocking DemystifiedMocking Demystified
Mocking Demystified
 
WordPress London 16 May 2012 - You don’t know query
WordPress London 16 May 2012 - You don’t know queryWordPress London 16 May 2012 - You don’t know query
WordPress London 16 May 2012 - You don’t know query
 

Destacado

Firewall in Perl by Chankey Pathak
Firewall in Perl by Chankey PathakFirewall in Perl by Chankey Pathak
Firewall in Perl by Chankey PathakChankey Pathak
 
Moose Hacking Guide
Moose Hacking GuideMoose Hacking Guide
Moose Hacking Guideguest6b8f09
 
Moose - YAPC::NA 2012
Moose - YAPC::NA 2012Moose - YAPC::NA 2012
Moose - YAPC::NA 2012xSawyer
 
Introduction to Perl MAGIC
Introduction to Perl MAGICIntroduction to Perl MAGIC
Introduction to Perl MAGICguest6b8f09
 
Introduction to OO Perl with Moose
Introduction to OO Perl with MooseIntroduction to OO Perl with Moose
Introduction to OO Perl with MooseDave Cross
 
YAPC::Asia 2014 - 半端なPHPDisでPHPerに陰で笑われないためのPerl Monger向け最新PHP事情
YAPC::Asia 2014 - 半端なPHPDisでPHPerに陰で笑われないためのPerl Monger向け最新PHP事情YAPC::Asia 2014 - 半端なPHPDisでPHPerに陰で笑われないためのPerl Monger向け最新PHP事情
YAPC::Asia 2014 - 半端なPHPDisでPHPerに陰で笑われないためのPerl Monger向け最新PHP事情Junichi Ishida
 
Great Tools Heavily Used In Japan, You Don't Know.
Great Tools Heavily Used In Japan, You Don't Know.Great Tools Heavily Used In Japan, You Don't Know.
Great Tools Heavily Used In Japan, You Don't Know.Junichi Ishida
 
Perl.Hacks.On.Vim
Perl.Hacks.On.VimPerl.Hacks.On.Vim
Perl.Hacks.On.VimLin Yo-An
 
10 books that every developer must read
10 books that every developer must read10 books that every developer must read
10 books that every developer must readGanesh Samarthyam
 

Destacado (10)

Firewall in Perl by Chankey Pathak
Firewall in Perl by Chankey PathakFirewall in Perl by Chankey Pathak
Firewall in Perl by Chankey Pathak
 
Moose Hacking Guide
Moose Hacking GuideMoose Hacking Guide
Moose Hacking Guide
 
Moose - YAPC::NA 2012
Moose - YAPC::NA 2012Moose - YAPC::NA 2012
Moose - YAPC::NA 2012
 
Introduction to Perl MAGIC
Introduction to Perl MAGICIntroduction to Perl MAGIC
Introduction to Perl MAGIC
 
Introduction to OO Perl with Moose
Introduction to OO Perl with MooseIntroduction to OO Perl with Moose
Introduction to OO Perl with Moose
 
YAPC::Asia 2014 - 半端なPHPDisでPHPerに陰で笑われないためのPerl Monger向け最新PHP事情
YAPC::Asia 2014 - 半端なPHPDisでPHPerに陰で笑われないためのPerl Monger向け最新PHP事情YAPC::Asia 2014 - 半端なPHPDisでPHPerに陰で笑われないためのPerl Monger向け最新PHP事情
YAPC::Asia 2014 - 半端なPHPDisでPHPerに陰で笑われないためのPerl Monger向け最新PHP事情
 
Great Tools Heavily Used In Japan, You Don't Know.
Great Tools Heavily Used In Japan, You Don't Know.Great Tools Heavily Used In Japan, You Don't Know.
Great Tools Heavily Used In Japan, You Don't Know.
 
Perl.Hacks.On.Vim
Perl.Hacks.On.VimPerl.Hacks.On.Vim
Perl.Hacks.On.Vim
 
10 books that every developer must read
10 books that every developer must read10 books that every developer must read
10 books that every developer must read
 
The Programmer
The ProgrammerThe Programmer
The Programmer
 

Similar a Intro To Moose

Mojolicious - Perl Framework for the Real-Time Web (Lightning Talk)
Mojolicious - Perl Framework for the Real-Time Web (Lightning Talk)Mojolicious - Perl Framework for the Real-Time Web (Lightning Talk)
Mojolicious - Perl Framework for the Real-Time Web (Lightning Talk)Dotan Dimet
 
Mojolicious. Веб в коробке!
Mojolicious. Веб в коробке!Mojolicious. Веб в коробке!
Mojolicious. Веб в коробке!Anatoly Sharifulin
 
Introducing Assetic: Asset Management for PHP 5.3
Introducing Assetic: Asset Management for PHP 5.3Introducing Assetic: Asset Management for PHP 5.3
Introducing Assetic: Asset Management for PHP 5.3Kris Wallsmith
 
MTDDC 2010.2.5 Tokyo - Brand new API
MTDDC 2010.2.5 Tokyo - Brand new APIMTDDC 2010.2.5 Tokyo - Brand new API
MTDDC 2010.2.5 Tokyo - Brand new APISix Apart KK
 
You Don't Know Query - WordCamp Portland 2011
You Don't Know Query - WordCamp Portland 2011You Don't Know Query - WordCamp Portland 2011
You Don't Know Query - WordCamp Portland 2011andrewnacin
 
DBIx::Skinnyと仲間たち
DBIx::Skinnyと仲間たちDBIx::Skinnyと仲間たち
DBIx::Skinnyと仲間たちRyo Miyake
 
Php Code Audits (PHP UK 2010)
Php Code Audits (PHP UK 2010)Php Code Audits (PHP UK 2010)
Php Code Audits (PHP UK 2010)Damien Seguy
 
You Don't Know Query (WordCamp Netherlands 2012)
You Don't Know Query (WordCamp Netherlands 2012)You Don't Know Query (WordCamp Netherlands 2012)
You Don't Know Query (WordCamp Netherlands 2012)andrewnacin
 
Perl Teach-In (part 2)
Perl Teach-In (part 2)Perl Teach-In (part 2)
Perl Teach-In (part 2)Dave Cross
 
Selenium sandwich-3: Being where you aren't.
Selenium sandwich-3: Being where you aren't.Selenium sandwich-3: Being where you aren't.
Selenium sandwich-3: Being where you aren't.Workhorse Computing
 
Adventures in Optimization
Adventures in OptimizationAdventures in Optimization
Adventures in OptimizationDavid Golden
 
Dirty Secrets of the PHP SOAP Extension
Dirty Secrets of the PHP SOAP ExtensionDirty Secrets of the PHP SOAP Extension
Dirty Secrets of the PHP SOAP ExtensionAdam Trachtenberg
 
Introducing CakeEntity
Introducing CakeEntityIntroducing CakeEntity
Introducing CakeEntityBasuke Suzuki
 
DrupalCamp Foz - Novas APIs Drupal 7
DrupalCamp Foz - Novas APIs Drupal 7DrupalCamp Foz - Novas APIs Drupal 7
DrupalCamp Foz - Novas APIs Drupal 7chuvainc
 

Similar a Intro To Moose (20)

Perl object ?
Perl object ?Perl object ?
Perl object ?
 
Blog Hacks 2011
Blog Hacks 2011Blog Hacks 2011
Blog Hacks 2011
 
Mojolicious - Perl Framework for the Real-Time Web (Lightning Talk)
Mojolicious - Perl Framework for the Real-Time Web (Lightning Talk)Mojolicious - Perl Framework for the Real-Time Web (Lightning Talk)
Mojolicious - Perl Framework for the Real-Time Web (Lightning Talk)
 
Mojolicious. Веб в коробке!
Mojolicious. Веб в коробке!Mojolicious. Веб в коробке!
Mojolicious. Веб в коробке!
 
php2.pptx
php2.pptxphp2.pptx
php2.pptx
 
Introducing Assetic: Asset Management for PHP 5.3
Introducing Assetic: Asset Management for PHP 5.3Introducing Assetic: Asset Management for PHP 5.3
Introducing Assetic: Asset Management for PHP 5.3
 
Wp query
Wp queryWp query
Wp query
 
MTDDC 2010.2.5 Tokyo - Brand new API
MTDDC 2010.2.5 Tokyo - Brand new APIMTDDC 2010.2.5 Tokyo - Brand new API
MTDDC 2010.2.5 Tokyo - Brand new API
 
You Don't Know Query - WordCamp Portland 2011
You Don't Know Query - WordCamp Portland 2011You Don't Know Query - WordCamp Portland 2011
You Don't Know Query - WordCamp Portland 2011
 
DBIx::Skinnyと仲間たち
DBIx::Skinnyと仲間たちDBIx::Skinnyと仲間たち
DBIx::Skinnyと仲間たち
 
Php Code Audits (PHP UK 2010)
Php Code Audits (PHP UK 2010)Php Code Audits (PHP UK 2010)
Php Code Audits (PHP UK 2010)
 
About Data::ObjectDriver
About Data::ObjectDriverAbout Data::ObjectDriver
About Data::ObjectDriver
 
You Don't Know Query (WordCamp Netherlands 2012)
You Don't Know Query (WordCamp Netherlands 2012)You Don't Know Query (WordCamp Netherlands 2012)
You Don't Know Query (WordCamp Netherlands 2012)
 
Perl Teach-In (part 2)
Perl Teach-In (part 2)Perl Teach-In (part 2)
Perl Teach-In (part 2)
 
Selenium sandwich-3: Being where you aren't.
Selenium sandwich-3: Being where you aren't.Selenium sandwich-3: Being where you aren't.
Selenium sandwich-3: Being where you aren't.
 
Adventures in Optimization
Adventures in OptimizationAdventures in Optimization
Adventures in Optimization
 
Dirty Secrets of the PHP SOAP Extension
Dirty Secrets of the PHP SOAP ExtensionDirty Secrets of the PHP SOAP Extension
Dirty Secrets of the PHP SOAP Extension
 
Webdriver
WebdriverWebdriver
Webdriver
 
Introducing CakeEntity
Introducing CakeEntityIntroducing CakeEntity
Introducing CakeEntity
 
DrupalCamp Foz - Novas APIs Drupal 7
DrupalCamp Foz - Novas APIs Drupal 7DrupalCamp Foz - Novas APIs Drupal 7
DrupalCamp Foz - Novas APIs Drupal 7
 

Último

Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfSeasiaInfotech2
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 

Último (20)

Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdf
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 

Intro To Moose

  • 1. Introduction to Object Oriented Programming in Perl with Moose. Introduction to Object Oriented Programming with Moose
  • 2. What is an Object? • Holds information about it’s self • Does stuff (functions) • defined by a class (not an object)
  • 3. OO in Perl? • DateTime • WWW::Mechanize • DBI • IO::Handle
  • 4. Often created with new • my $mech = WWW::Mechanize->new • my $dt = DateTime->new(year => 2000, month => ...);
  • 5. But not always • my $dt = DateTime->now(time_zone => ‘America/Chicago’);
  • 6. Holds information • my $mech = WWW::Mechanize->new • $mech->get($url) • my $content = $mech->content()
  • 7. Not an object. • use Cwd; • my $dir = getcwd();
  • 8. Some times globals point the need for an object #!/usr/bin/env perl use strict; use warnings; use WWW::Mechanize; my $base = ‘http://www.google.com/search?q=’; my $mech = $mech->new; print query(“perl”) print query(“moose”) sub query { my $query = shift; $mech->get($url . $query); return $mech->content; }
  • 9. Becomes.... package SearchEngine; use Moose; use WWW::Mechanize; has ‘url_base’ => (isa => Str, is => ‘rw’, default => ‘http://www.google.com/search?q=’); has ‘mech’ => (isa => Object, is => ‘ro’, default => sub {WWW::Mechanize->new}); sub query { my $self = shift; my $query = shift; $self->mech->get($self->url_base . $query); return $self->mech->content; } 1;
  • 10. Now I can query away use SearchEngine; my $google = SearchEngine->new; my $alta = SearchEngine->new(url_base => ‘http://www.altavista.com/web/results?q=’); print $google->query(‘perl’); print $alta->query(‘perl’); print $google->query(‘Moose’); print $alta->query(‘Moose’);
  • 11. Change engines after new use SearchEngine; my $search = SearchEngine->new; # defaults to google $search->url_base(‘http://www.altavista.com/web/results?q=’); print $search->query(‘perl’);
  • 12. Moose out of the box • Type constraints ( ) http://tinyurl.com/moose-types • use strict; • use warnings • don’t have to define new • Delegation
  • 13. package SearchEngine; Delegation use Moose; use WWW::Mechanize; has ‘url_base’ => (isa => Str, is => ‘rw’, default => ‘http://www.google.com/search?q=’); has ‘mech’ => (isa => Object, is => ‘ro’, default => sub {WWW::Mechanize->new}, handles => { ‘content’ => ‘content’ } handles => { ‘get’ => ‘get’ } ); sub query { my $self = shift; my $query = shift; #$self->mech->get($self->url_base . $query); $self->get($self->url_base . $query); #return $self->mech->content; return $self->content; } 1;
  • 14. Why Moose? • See slide 25 - Intro to Moose
  • 15. Why Moose • Moose means less code • (less code == less bugs) • Less tests • (why test what moose already does) • over 6000 unit tests • 0.24 seconds load time • ~ 3mb for perl+moose
  • 16. No Moose •no Moose at the end of a package is a best practice • Just do it
  • 17. Immutability Stevan's Incantation of Fleet- Footedness package Person; use Moose; __PACKAGE__->meta->make_immutable;
  • 18. What make_immutable does Magic • Uses eval to "inline" a constructor • Memoizes a lot of meta-information • Makes loading your class slower • Makes object creation much faster
  • 19. no immutable Moose; package SearchEngine; use Moose; use WWW::Mechanize; has ‘url_base’ => (isa => Str, is => ‘rw’, default => ‘http://www.google.com/search?q=’); has ‘mech’ => (isa => Object, is => ‘ro’, default => sub {WWW::Mechanize->new}, handles => { ‘content’ => ‘content’ } handles => { ‘get’ => ‘get’ } ); sub query { my $self = shift; my $query = shift; #$self->mech->get($self->url_base . $query); $self->get($self->url_base . $query); #return $self->mech->content; return $self->content; } __PACKAGE__->meta->make_immutable no Moose; 1;
  • 20. Moose is cool for tests! # no_net.t package pseudomech; sub new{return bless {}} sub get{ my $self = shift; $self->{query} = shift; } sub content { return shift->{query} . “ response”; } package main; use Test::More tests => 2; use SearchEngine; my $google = SearchEngine->new(mech => pseudomech->new); is($google->query(‘perl’), ‘perl response’); is($google->query(‘Moose’), ‘Moose response’); exit;
  • 21. Roles • Usually what you want when you try to do inheritance • lets 1 class take on the features of multiple packages.
  • 22. More Reading • Moose Cookbook (heavy on the inheritance) • http://search.cpan.org/dist/Moose/lib/ Moose/Cookbook.pod • Moose Website • http://moose.perl.org

Notas del editor