SlideShare a Scribd company logo
1 of 12
Learning Moose
Taking Perl Objects to the Next Level


Drew Stephens <drew@dinomite.net>
Classic Perl Objects
package Horse;

sub new {
   my $class = shift; my ($name, $legs) = @_;
   my $self = {name => $name; legs => $legs;}
   return bless $self, $class;
}

sub name {
   my $self = shift;
   if (@_) {$self->{name} = shift;}
   return $self->{name};
}
                                                drew@dinomite.net
It’s Crap
Enter Moose

Free constructor, accessors, and modifiers
Attribute type enforcement with parameter checking
Read-only attributes
Meta-programming
Pretty syntax



                                                     drew@dinomite.net
What’s a Horse Look Like?
    package Horse;
    use Moose;
    has 'name' => (
       is => 'rw',
       isa => ‘Str’,
       required => 1,
    );
    has 'legs' => (
       is => 'ro',
       isa => ‘Int’,
       default => 4,
    );
    1;

Randal L. Schwartz: Linux Magazine Column 94: The Moose is Flying. http://is.gd/50Ezi   drew@dinomite.net
Making a Horse

    use Horse;

    my $ed = Horse->new(
       name => ‘Mr. Ed’
    );

    print $ed->name() . " has " . $ed->legs() . " legsn";




Randal L. Schwartz: Linux Magazine Column 94: The Moose is Flying. http://is.gd/50Ezi   drew@dinomite.net
Abstract Classes
    package Animal;
    use Moose::Role;
    has 'name' => (
        is => 'rw', isa => ‘Str’, required => 1,
    );
    has 'legs' => (
        is => 'ro', isa => ‘Int’, default => 4,
    );
    requires 'sound';
    sub speak {
        my $self = shift;
        print $self->name, " goes ", $self->sound, "n";
    }
Randal L. Schwartz: Linux Magazine Column 94: The Moose is Flying. http://is.gd/50Ezi   drew@dinomite.net
Inherited Horse
    package Horse;
    use Moose;
    with 'Animal';
    sub sound { 'neigh' }
    1;

    $ed->speak(); # Mr. Ed goes neigh




Randal L. Schwartz: Linux Magazine Column 94: The Moose is Flying. http://is.gd/50Ezi   drew@dinomite.net
Extending Parent Methods
    package Mouse;
    use Moose;
    with 'Animal';

    sub sound { 'squeak' }

    after 'speak' => sub {
        print "[but you can barely hear it!]n";
    };

    # A mouse goes squeak
    # [but you can barely hear it!]

Randal L. Schwartz: Linux Magazine Column 94: The Moose is Flying. http://is.gd/50Ezi   drew@dinomite.net
Type Coercion
    coerce 'HistoricalDateTime'
       => from 'Str'
       => via {
          require DateTime::Format::DateManip;
          DateTime::Format::DateManip->parse_datetime($_);
       };

    has 'born' => (
       is => 'ro',
       isa => 'HistoricalDateTime',
       coerce => 1,
    );

Randal L. Schwartz: Linux Magazine Column 95: The Moose is Flying (part 2). http://is.gd/50Nfm   drew@dinomite.net
Fill The Barn
    my $newbie = Horse->new(
       born => 'yesterday',
       name => 'Newbie'
    );
    $newbie->speak(); # Newbie goes neigh

    my $mouse = Mouse->new(
       name => 'Minnie',
       born => '3/14/1929'
    );
    $mouse->speak(); # Minnie goes squeak
                     # [but you can barely hear it!]

Randal L. Schwartz: Linux Magazine Column 95: The Moose is Flying (part 2). http://is.gd/50Nfm   drew@dinomite.net
References

Damian Conway: Perl Best Practices. O’Reilly, 2009

Randal L. Schwartz: Inside Out Objects.
   http://www.stonehenge.com/merlyn/UnixReview/col63.html

Jay Kuri: A Gentle Introduction to Moose.
    http://www.catalyzed.org/2009/06/a-gentle-introduction-to-moose.html

Randal L. Schwartz: The Moose is Flying.
   http://www.stonehenge.com/merlyn/LinuxMag/col94.html

Moose.pm on CPAN (v0.93).
   http://search.cpan.org/dist/Moose/lib/Moose/Manual.pod




                                                                           drew@dinomite.net

More Related Content

Recently uploaded

Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
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
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 

Recently uploaded (20)

Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
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
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 

Featured

AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 

Featured (20)

AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 

Learning Moose SHDH 36 Lightning Talk

  • 1. Learning Moose Taking Perl Objects to the Next Level Drew Stephens <drew@dinomite.net>
  • 2. Classic Perl Objects package Horse; sub new { my $class = shift; my ($name, $legs) = @_; my $self = {name => $name; legs => $legs;} return bless $self, $class; } sub name { my $self = shift; if (@_) {$self->{name} = shift;} return $self->{name}; } drew@dinomite.net
  • 4. Enter Moose Free constructor, accessors, and modifiers Attribute type enforcement with parameter checking Read-only attributes Meta-programming Pretty syntax drew@dinomite.net
  • 5. What’s a Horse Look Like? package Horse; use Moose; has 'name' => ( is => 'rw', isa => ‘Str’, required => 1, ); has 'legs' => ( is => 'ro', isa => ‘Int’, default => 4, ); 1; Randal L. Schwartz: Linux Magazine Column 94: The Moose is Flying. http://is.gd/50Ezi drew@dinomite.net
  • 6. Making a Horse use Horse; my $ed = Horse->new( name => ‘Mr. Ed’ ); print $ed->name() . " has " . $ed->legs() . " legsn"; Randal L. Schwartz: Linux Magazine Column 94: The Moose is Flying. http://is.gd/50Ezi drew@dinomite.net
  • 7. Abstract Classes package Animal; use Moose::Role; has 'name' => ( is => 'rw', isa => ‘Str’, required => 1, ); has 'legs' => ( is => 'ro', isa => ‘Int’, default => 4, ); requires 'sound'; sub speak { my $self = shift; print $self->name, " goes ", $self->sound, "n"; } Randal L. Schwartz: Linux Magazine Column 94: The Moose is Flying. http://is.gd/50Ezi drew@dinomite.net
  • 8. Inherited Horse package Horse; use Moose; with 'Animal'; sub sound { 'neigh' } 1; $ed->speak(); # Mr. Ed goes neigh Randal L. Schwartz: Linux Magazine Column 94: The Moose is Flying. http://is.gd/50Ezi drew@dinomite.net
  • 9. Extending Parent Methods package Mouse; use Moose; with 'Animal'; sub sound { 'squeak' } after 'speak' => sub { print "[but you can barely hear it!]n"; }; # A mouse goes squeak # [but you can barely hear it!] Randal L. Schwartz: Linux Magazine Column 94: The Moose is Flying. http://is.gd/50Ezi drew@dinomite.net
  • 10. Type Coercion coerce 'HistoricalDateTime' => from 'Str' => via { require DateTime::Format::DateManip; DateTime::Format::DateManip->parse_datetime($_); }; has 'born' => ( is => 'ro', isa => 'HistoricalDateTime', coerce => 1, ); Randal L. Schwartz: Linux Magazine Column 95: The Moose is Flying (part 2). http://is.gd/50Nfm drew@dinomite.net
  • 11. Fill The Barn my $newbie = Horse->new( born => 'yesterday', name => 'Newbie' ); $newbie->speak(); # Newbie goes neigh my $mouse = Mouse->new( name => 'Minnie', born => '3/14/1929' ); $mouse->speak(); # Minnie goes squeak # [but you can barely hear it!] Randal L. Schwartz: Linux Magazine Column 95: The Moose is Flying (part 2). http://is.gd/50Nfm drew@dinomite.net
  • 12. References Damian Conway: Perl Best Practices. O’Reilly, 2009 Randal L. Schwartz: Inside Out Objects. http://www.stonehenge.com/merlyn/UnixReview/col63.html Jay Kuri: A Gentle Introduction to Moose. http://www.catalyzed.org/2009/06/a-gentle-introduction-to-moose.html Randal L. Schwartz: The Moose is Flying. http://www.stonehenge.com/merlyn/LinuxMag/col94.html Moose.pm on CPAN (v0.93). http://search.cpan.org/dist/Moose/lib/Moose/Manual.pod drew@dinomite.net

Editor's Notes

  1. When non-Perl folks look at this, they see a high ratio of non-word characters, lots of existentialisim, and some religious bullshit&amp;#x2014;they&amp;#x2019;re thinking one thing&amp;#x2026;
  2. Instead of using SUPER::, we can extend the parent method