SlideShare a Scribd company logo
1 of 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

More Related Content

What's hot

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
 

What's hot (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
 

Viewers also liked

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
 

Viewers also liked (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 to 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 to 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
 

Recently uploaded

ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdfChristopherTHyatt
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 

Recently uploaded (20)

ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 

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

Editor's Notes