This document discusses Perl objects and object-oriented programming in Perl. It begins by explaining some of the problems with manipulating data without objects, such as needing to know exact key names and being unable to change key names or storage locations without updating all code. It then discusses what an object is and some benefits of using objects such as code organization, reducing repetition, and making code easier to read, share, test and maintain. The document goes on to explain object-oriented concepts like inheritance, encapsulation, and type checking. It provides examples of different object libraries for Perl like Moose, Moo, and Class::XSAccessor. It also discusses when it may not be appropriate to use objects, such as for performance-
Temporary Cache Assistance (Transients API): WordCamp Birmingham 2014Cliff Seal
WordPress has a few built-in ways to cache data that enable rapid development. Understanding your options and how to use them properly in your context is crucial to a performant and scalable site. The Transients API provides a powerful and easy way to store data with an expiration, and it comes with a few under-the-hood perks as well.
Join me in looking at the benefits you can gain from understanding and implementing “transients”. When we’re done, you’ll know what this API is, when it should be used, how to use it, and how to scale it. I’ll give real, useful code examples that you can implement immediately—without boring you to death. You’ll be able to do anything from caching data from a external API (like recent tweets) to storing a large, complex query.
We’ll also cover some of the more obscure aspects of this method, like:
-Object caching/Memcached
-Autoloading
-Race Conditions
-Expired transient cleanup
-Options table bloat
Do yourself and your visitors a favor by utilizing the Transients API. And, as you’ll see in this session, knowing how to use it will make all WordPress’s caching techniques easy to implement.
The current status of the Corinna OOP proposal for the Perl programming language.
After years of design and discussion, the Perl Steering Committee has accepted the Corinna RFC (in a scaled-back initial form) for inclusion in the Perl language.
This talk gives the history of the proposal and where we're going from here.
PHP 5.3 and Lithium: the most rad php frameworkG Woo
Presentation given to the Orange County PHP meetup on Feb 24 2010. The presentation covers the new features in php 5.3 and goes on to show how they are used in Lithium, the most rad php framework.
What makes your code slow? How do you make it faster? And how do you prove it?
This talk will describe my adventures benchmarking and optimizing ordered hashes in Perl, culminating in the release of Hash::Ordered (http://p3rl.org/Hash::Ordered) — which outperforms all other CPAN alternatives, often by a substantial margin. We will cover:
* How to customize Benchmark.pm
* How and why to benchmark at different scales
* Why tied anything in Perl is a horrible idea
* How ordered hashes got faster from a simple algorithm change
Models and Service Layers, Hemoglobin and HobgoblinsRoss Tuck
As presented at ZendCon 2014, AmsterdamPHP, PHPBenelux 2014, Sweetlake PHP and PHP Northwest 2013, an overview of some different patterns for integrating and managing logic throughout your application.
Temporary Cache Assistance (Transients API): WordCamp Birmingham 2014Cliff Seal
WordPress has a few built-in ways to cache data that enable rapid development. Understanding your options and how to use them properly in your context is crucial to a performant and scalable site. The Transients API provides a powerful and easy way to store data with an expiration, and it comes with a few under-the-hood perks as well.
Join me in looking at the benefits you can gain from understanding and implementing “transients”. When we’re done, you’ll know what this API is, when it should be used, how to use it, and how to scale it. I’ll give real, useful code examples that you can implement immediately—without boring you to death. You’ll be able to do anything from caching data from a external API (like recent tweets) to storing a large, complex query.
We’ll also cover some of the more obscure aspects of this method, like:
-Object caching/Memcached
-Autoloading
-Race Conditions
-Expired transient cleanup
-Options table bloat
Do yourself and your visitors a favor by utilizing the Transients API. And, as you’ll see in this session, knowing how to use it will make all WordPress’s caching techniques easy to implement.
The current status of the Corinna OOP proposal for the Perl programming language.
After years of design and discussion, the Perl Steering Committee has accepted the Corinna RFC (in a scaled-back initial form) for inclusion in the Perl language.
This talk gives the history of the proposal and where we're going from here.
PHP 5.3 and Lithium: the most rad php frameworkG Woo
Presentation given to the Orange County PHP meetup on Feb 24 2010. The presentation covers the new features in php 5.3 and goes on to show how they are used in Lithium, the most rad php framework.
What makes your code slow? How do you make it faster? And how do you prove it?
This talk will describe my adventures benchmarking and optimizing ordered hashes in Perl, culminating in the release of Hash::Ordered (http://p3rl.org/Hash::Ordered) — which outperforms all other CPAN alternatives, often by a substantial margin. We will cover:
* How to customize Benchmark.pm
* How and why to benchmark at different scales
* Why tied anything in Perl is a horrible idea
* How ordered hashes got faster from a simple algorithm change
Models and Service Layers, Hemoglobin and HobgoblinsRoss Tuck
As presented at ZendCon 2014, AmsterdamPHP, PHPBenelux 2014, Sweetlake PHP and PHP Northwest 2013, an overview of some different patterns for integrating and managing logic throughout your application.
Una panoramica su Net::Amazon::EC2 e Net::RackSpace::Servers. Potete trovare la presentazione con le note qui: http://polettix.s3.amazonaws.com/IPW2011/nubilus-perl-1.1-note.pdf
The IoC Hydra - Dutch PHP Conference 2016Kacper Gunia
Slides from my talk presented during Dutch PHP Conference in Amsterdam - 25 June 2016
More Domain-Driven Design related content at: https://domaincentric.net/
Caching and Scaling WordPress using Fragment CachingErick Hitter
Using what I’ve learned working on the WordPress.com VIP platform, this presentation discusses caching techniques applicable to WordPress installations of almost any size.
Presented February 18, 2012 at WordCamp Miami.
Original HTML5 slides are available at http://www.ethitter.com/2012/02/caching-and-scaling-wcmia/.
Closing keynote, as presented at Codemotion 2014, LaraconEU 2014, Redevelop 2014, CodeConnexx 2013 and PHP North East 2014.
This presentation makes a reference to a reading list I received. For those interested, the release consists of most of the general classics, such as Gang Of Four "Design Patterns", The Pragmatic Programmer, Structure and Interpretation of Computer Programs, Domain Driven Design and a few others. The actual list remains tucked away in a box somewhere.
Especially when looking at WordPress as a potential platform for web apps, understanding proper caching techniques is a must—and the Transients API is a powerful tool that sometimes goes unnoticed.
We’ll cover the basics and see easy examples, and then discuss common places where this method can be most helpful, like large, complex queries or pulling from an external API. We’ll also get into the details of the API, covering concepts like object caching, autoloading, and see some examples of more advanced setups.
PHP 7 – What changed internally? (Forum PHP 2015)Nikita Popov
One of the main selling points of PHP 7 is greatly improved performance, with many real-world applications now running twice as fast… But where do these improvements come from?
At the core of PHP 7 lies an engine rewrite with focus on improving memory usage and performance. This talk provides an overview of the most significant changes, briefly covering everything from data structure changes, over enhancements in the executor, to the new compiler implementation.
Temporary Cache Assistance (Transients API): WordCamp Phoenix 2014Cliff Seal
We’ll cover the basics of the Transients API, see basic examples, and then discuss common places where this method can be most helpful, like large, complex queries or pulling from an external API. We’ll also discuss how this type of caching is unique, when to use it, and how to scale it for big bursts of traffic.
Follow along with the code examples inside a working plugin: http://logoscreative.co/wcphx14/
Persistence is one of the most important part in a PHP project. Persisting data to a database came with PHP/FI and its MySQL support. From native extensions and PHP4 database abstraction libraries to PDO and modern ORM frameworks, you will (re)discover how persistence has evolved during the last decade. This talk will also introduce the future of data persistence with the growing success of alternative storage engines.
This session introduces most well known design patterns to build PHP classes and objects that need to store and fetch data from a relational databases. The session will describe the difference between of the Active Record, the Table and Row Data Gateway and the Data Mapper pattern. We will also examine some technical advantages and drawbacks of these implementations. This talk will expose some of the best PHP tools, which ease database interactions and are built on top of these patterns.
Una panoramica su Net::Amazon::EC2 e Net::RackSpace::Servers. Potete trovare la presentazione con le note qui: http://polettix.s3.amazonaws.com/IPW2011/nubilus-perl-1.1-note.pdf
The IoC Hydra - Dutch PHP Conference 2016Kacper Gunia
Slides from my talk presented during Dutch PHP Conference in Amsterdam - 25 June 2016
More Domain-Driven Design related content at: https://domaincentric.net/
Caching and Scaling WordPress using Fragment CachingErick Hitter
Using what I’ve learned working on the WordPress.com VIP platform, this presentation discusses caching techniques applicable to WordPress installations of almost any size.
Presented February 18, 2012 at WordCamp Miami.
Original HTML5 slides are available at http://www.ethitter.com/2012/02/caching-and-scaling-wcmia/.
Closing keynote, as presented at Codemotion 2014, LaraconEU 2014, Redevelop 2014, CodeConnexx 2013 and PHP North East 2014.
This presentation makes a reference to a reading list I received. For those interested, the release consists of most of the general classics, such as Gang Of Four "Design Patterns", The Pragmatic Programmer, Structure and Interpretation of Computer Programs, Domain Driven Design and a few others. The actual list remains tucked away in a box somewhere.
Especially when looking at WordPress as a potential platform for web apps, understanding proper caching techniques is a must—and the Transients API is a powerful tool that sometimes goes unnoticed.
We’ll cover the basics and see easy examples, and then discuss common places where this method can be most helpful, like large, complex queries or pulling from an external API. We’ll also get into the details of the API, covering concepts like object caching, autoloading, and see some examples of more advanced setups.
PHP 7 – What changed internally? (Forum PHP 2015)Nikita Popov
One of the main selling points of PHP 7 is greatly improved performance, with many real-world applications now running twice as fast… But where do these improvements come from?
At the core of PHP 7 lies an engine rewrite with focus on improving memory usage and performance. This talk provides an overview of the most significant changes, briefly covering everything from data structure changes, over enhancements in the executor, to the new compiler implementation.
Temporary Cache Assistance (Transients API): WordCamp Phoenix 2014Cliff Seal
We’ll cover the basics of the Transients API, see basic examples, and then discuss common places where this method can be most helpful, like large, complex queries or pulling from an external API. We’ll also discuss how this type of caching is unique, when to use it, and how to scale it for big bursts of traffic.
Follow along with the code examples inside a working plugin: http://logoscreative.co/wcphx14/
Persistence is one of the most important part in a PHP project. Persisting data to a database came with PHP/FI and its MySQL support. From native extensions and PHP4 database abstraction libraries to PDO and modern ORM frameworks, you will (re)discover how persistence has evolved during the last decade. This talk will also introduce the future of data persistence with the growing success of alternative storage engines.
This session introduces most well known design patterns to build PHP classes and objects that need to store and fetch data from a relational databases. The session will describe the difference between of the Active Record, the Table and Row Data Gateway and the Data Mapper pattern. We will also examine some technical advantages and drawbacks of these implementations. This talk will expose some of the best PHP tools, which ease database interactions and are built on top of these patterns.
This is the Moose talk I gave at YAPC::NA 2012.
It included a practical example of a Moose objects code, a simple app called Comican. The code is not available online. If you want it, just email me (sawyer ATT cpan DOTT org).
Can't Miss Features of PHP 5.3 and 5.4Jeff Carouth
If you're like me you remember the days of PHP3 and PHP4; you remember when PHP5 was released, and how it was touted to change to your life. It's still changing and there are some features of PHP 5.3 and new ones coming with PHP 5.4 that will improve your code readability and reusability. Let's look at some touted features such as closures, namespaces, and traits, as well as some features being discussed for future releases.
Eloquent è uno strumento potentissimo: permette di velocizzare, e di molto, lo sviluppo di applicazioni web offrendoti un’interfaccia molto chiara e intuitiva. Per la prototipazione rapida è il massimo. Tuttavia, non appena l’applicazione cresce di dimensione, la situazione rischia di esploderci in mano in quanto Eloquent soffre di tutti i limiti di un Active Record. Un’alternativa a questo pattern è il Data Mapper, implementato in maniera eccellente da Doctrine. In questo talk vedremo quindi come integrare Doctrine all'interno di Laravel e verrà dato qualche spunto su come strutturare un’architettura molto più solida.
Using Moose provides many immediate and obvious benefits, starting with the
obviation of typing "use strict" and "use warnings" in your classes.
The real power of Moose, however, rests in its extensibility. By subclassing
Moose's metaclasses, you can augment and change Moose's behavior to suit your
application's needs. This extensibility is powered by the meta-object protocol
of Moose's foundation, Class::MOP.
The motivating example for extending Moose will be the creation of a small web
framework to empower a Twitter-alike. The focus will be creating meta-level
roles so that metaclasses may select exactly which changes in behavior they
wish to exhibit. Modules that will be used include Moose::Exporter (to define
sugary keywords) and Moose::Util::MetaRole (to extend classes composably).
Experience with using Moose to create regular classes is expected. Having some
familiarity with roles will let you get more out of the talk. No experience
with metaprogramming is required.
With more and more sites falling victim to data theft, you've probably read the list of things (not) to do to write secure code. But what else should you do to make sure your code and the rest of your web stack is secure ? In this tutorial we'll go through the basic and more advanced techniques of securing your web and database servers, securing your backend PHP code and your frontend javascript code. We'll also look at how you can build code that detects and blocks intrusion attempts and a bunch of other tips and tricks to make sure your customer data stays secure.
With more and more sites falling victim to data theft, you've probably read the list of things (not) to do to write secure code. But what else should you do to make sure your code and the rest of your web stack is secure ? In this tutorial we'll go through the basic and more advanced techniques of securing your web and database servers, securing your backend PHP code and your frontend javascript code. We'll also look at how you can build code that detects and blocks intrusion attempts and a bunch of other tips and tricks to make sure your customer data stays secure.
With more and more sites falling victim to data theft, you've probably read the list of things (not) to do to write secure code. But what else should you do to make sure your code and the rest of your web stack is secure ? In this tutorial we'll go through the basic and more advanced techniques of securing your web and database servers, securing your backend PHP code and your frontend javascript code. We'll also look at how you can build code that detects and blocks intrusion attempts and a bunch of other tips and tricks to make sure your customer data stays secure.
Internationalizing CakePHP ApplicationsPierre MARTIN
Slides from the talk given by Mariano Iglesias during the CakeFest #3 - July 2009
Note: the original pdf and the code related to this talk can be found on cakephp.org (http://cakephp.org/downloads/CakeFest/CakeFest%203%20-%20Berlin%202009/Mariano%20Iglesias%20-%20Internationalizing%20CakePHP%20Applications)
Even nowadays, PHP code is mostly manually audited. Expert pore over actual code, in search for bugs or code smells. Actually, it is possible to have PHP do this work itself ! Strengthened with the internal Tokenizer, bolstered by the manual, it is able to scan thousands of lines of code, without getting bored, and bringing pragmatic pieces of wisdom: official manual recommendations, version migration, code pruning and security. In the end, it deliver a global overview of the code, without reading it.
This talk will show how it's possible to mock PerlOps using XS and provide a convenient Pure Perl hook for each of the file check -X.
Overload::FileCheck provides a way to mock one or more file checks. It is also possible to mock stat/lstat functions using "mock_all_from_stat" and let Overload::FileCheck mock for you for any other -X checks.
This is a very light introduction to perl internals and how perl store values as scalars using C struct.
Short introduction to copy on write strings: COWPV.
Representation of hashes: collision, split, grow...
How to pre-allocate memory for large hashes
Amazon::Dash::Button allows you to discover your mac address button and set a listener to run any custom actions when the button is clicked...
Lightning talk at The Perl Conference 2017 in Washington D.C.
Software Engineering, Software Consulting, Tech Lead.
Spring Boot, Spring Cloud, Spring Core, Spring JDBC, Spring Security,
Spring Transaction, Spring MVC,
Log4j, REST/SOAP WEB-SERVICES.
A Comprehensive Look at Generative AI in Retail App Testing.pdfkalichargn70th171
Traditional software testing methods are being challenged in retail, where customer expectations and technological advancements continually shape the landscape. Enter generative AI—a transformative subset of artificial intelligence technologies poised to revolutionize software testing.
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar
The European Union Agency for Law Enforcement Cooperation (Europol) has suffered an alleged data breach after a notorious threat actor claimed to have exfiltrated data from its systems. Infamous data leaker IntelBroker posted on the even more infamous BreachForums hacking forum, saying that Europol suffered a data breach this month.
The alleged breach affected Europol agencies CCSE, EC3, Europol Platform for Experts, Law Enforcement Forum, and SIRIUS. Infiltration of these entities can disrupt ongoing investigations and compromise sensitive intelligence shared among international law enforcement agencies.
However, this is neither the first nor the last activity of IntekBroker. We have compiled for you what happened in the last few days. To track such hacker activities on dark web sources like hacker forums, private Telegram channels, and other hidden platforms where cyber threats often originate, you can check SOCRadar’s Dark Web News.
Stay Informed on Threat Actors’ Activity on the Dark Web with SOCRadar!
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Globus
Large Language Models (LLMs) are currently the center of attention in the tech world, particularly for their potential to advance research. In this presentation, we'll explore a straightforward and effective method for quickly initiating inference runs on supercomputers using the vLLM tool with Globus Compute, specifically on the Polaris system at ALCF. We'll begin by briefly discussing the popularity and applications of LLMs in various fields. Following this, we will introduce the vLLM tool, and explain how it integrates with Globus Compute to efficiently manage LLM operations on Polaris. Attendees will learn the practical aspects of setting up and remotely triggering LLMs from local machines, focusing on ease of use and efficiency. This talk is ideal for researchers and practitioners looking to leverage the power of LLMs in their work, offering a clear guide to harnessing supercomputing resources for quick and effective LLM inference.
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Globus
The Earth System Grid Federation (ESGF) is a global network of data servers that archives and distributes the planet’s largest collection of Earth system model output for thousands of climate and environmental scientists worldwide. Many of these petabyte-scale data archives are located in proximity to large high-performance computing (HPC) or cloud computing resources, but the primary workflow for data users consists of transferring data, and applying computations on a different system. As a part of the ESGF 2.0 US project (funded by the United States Department of Energy Office of Science), we developed pre-defined data workflows, which can be run on-demand, capable of applying many data reduction and data analysis to the large ESGF data archives, transferring only the resultant analysis (ex. visualizations, smaller data files). In this talk, we will showcase a few of these workflows, highlighting how Globus Flows can be used for petabyte-scale climate analysis.
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxrickgrimesss22
Discover the essential features to incorporate in your Winzo clone app to boost business growth, enhance user engagement, and drive revenue. Learn how to create a compelling gaming experience that stands out in the competitive market.
How Recreation Management Software Can Streamline Your Operations.pptxwottaspaceseo
Recreation management software streamlines operations by automating key tasks such as scheduling, registration, and payment processing, reducing manual workload and errors. It provides centralized management of facilities, classes, and events, ensuring efficient resource allocation and facility usage. The software offers user-friendly online portals for easy access to bookings and program information, enhancing customer experience. Real-time reporting and data analytics deliver insights into attendance and preferences, aiding in strategic decision-making. Additionally, effective communication tools keep participants and staff informed with timely updates. Overall, recreation management software enhances efficiency, improves service delivery, and boosts customer satisfaction.
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamtakuyayamamoto1800
In this slide, we show the simulation example and the way to compile this solver.
In this solver, the Helmholtz equation can be solved by helmholtzFoam. Also, the Helmholtz equation with uniformly dispersed bubbles can be simulated by helmholtzBubbleFoam.
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Shahin Sheidaei
Games are powerful teaching tools, fostering hands-on engagement and fun. But they require careful consideration to succeed. Join me to explore factors in running and selecting games, ensuring they serve as effective teaching tools. Learn to maintain focus on learning objectives while playing, and how to measure the ROI of gaming in education. Discover strategies for pitching gaming to leadership. This session offers insights, tips, and examples for coaches, team leads, and enterprise leaders seeking to teach from simple to complex concepts.
Unleash Unlimited Potential with One-Time Purchase
BoxLang is more than just a language; it's a community. By choosing a Visionary License, you're not just investing in your success, you're actively contributing to the ongoing development and support of BoxLang.
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisGlobus
JASMIN is the UK’s high-performance data analysis platform for environmental science, operated by STFC on behalf of the UK Natural Environment Research Council (NERC). In addition to its role in hosting the CEDA Archive (NERC’s long-term repository for climate, atmospheric science & Earth observation data in the UK), JASMIN provides a collaborative platform to a community of around 2,000 scientists in the UK and beyond, providing nearly 400 environmental science projects with working space, compute resources and tools to facilitate their work. High-performance data transfer into and out of JASMIN has always been a key feature, with many scientists bringing model outputs from supercomputers elsewhere in the UK, to analyse against observational or other model data in the CEDA Archive. A growing number of JASMIN users are now realising the benefits of using the Globus service to provide reliable and efficient data movement and other tasks in this and other contexts. Further use cases involve long-distance (intercontinental) transfers to and from JASMIN, and collecting results from a mobile atmospheric radar system, pushing data to JASMIN via a lightweight Globus deployment. We provide details of how Globus fits into our current infrastructure, our experience of the recent migration to GCSv5.4, and of our interest in developing use of the wider ecosystem of Globus services for the benefit of our user community.
Code reviews are vital for ensuring good code quality. They serve as one of our last lines of defense against bugs and subpar code reaching production.
Yet, they often turn into annoying tasks riddled with frustration, hostility, unclear feedback and lack of standards. How can we improve this crucial process?
In this session we will cover:
- The Art of Effective Code Reviews
- Streamlining the Review Process
- Elevating Reviews with Automated Tools
By the end of this presentation, you'll have the knowledge on how to organize and improve your code review proces
First Steps with Globus Compute Multi-User EndpointsGlobus
In this presentation we will share our experiences around getting started with the Globus Compute multi-user endpoint. Working with the Pharmacology group at the University of Auckland, we have previously written an application using Globus Compute that can offload computationally expensive steps in the researcher's workflows, which they wish to manage from their familiar Windows environments, onto the NeSI (New Zealand eScience Infrastructure) cluster. Some of the challenges we have encountered were that each researcher had to set up and manage their own single-user globus compute endpoint and that the workloads had varying resource requirements (CPUs, memory and wall time) between different runs. We hope that the multi-user endpoint will help to address these challenges and share an update on our progress here.
In software engineering, the right architecture is essential for robust, scalable platforms. Wix has undergone a pivotal shift from event sourcing to a CRUD-based model for its microservices. This talk will chart the course of this pivotal journey.
Event sourcing, which records state changes as immutable events, provided robust auditing and "time travel" debugging for Wix Stores' microservices. Despite its benefits, the complexity it introduced in state management slowed development. Wix responded by adopting a simpler, unified CRUD model. This talk will explore the challenges of event sourcing and the advantages of Wix's new "CRUD on steroids" approach, which streamlines API integration and domain event management while preserving data integrity and system resilience.
Participants will gain valuable insights into Wix's strategies for ensuring atomicity in database updates and event production, as well as caching, materialization, and performance optimization techniques within a distributed system.
Join us to discover how Wix has mastered the art of balancing simplicity and extensibility, and learn how the re-adoption of the modest CRUD has turbocharged their development velocity, resilience, and scalability in a high-growth environment.
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Anthony Dahanne
Les Buildpacks existent depuis plus de 10 ans ! D’abord, ils étaient utilisés pour détecter et construire une application avant de la déployer sur certains PaaS. Ensuite, nous avons pu créer des images Docker (OCI) avec leur dernière génération, les Cloud Native Buildpacks (CNCF en incubation). Sont-ils une bonne alternative au Dockerfile ? Que sont les buildpacks Paketo ? Quelles communautés les soutiennent et comment ?
Venez le découvrir lors de cette session ignite
Developing Distributed High-performance Computing Capabilities of an Open Sci...Globus
COVID-19 had an unprecedented impact on scientific collaboration. The pandemic and its broad response from the scientific community has forged new relationships among public health practitioners, mathematical modelers, and scientific computing specialists, while revealing critical gaps in exploiting advanced computing systems to support urgent decision making. Informed by our team’s work in applying high-performance computing in support of public health decision makers during the COVID-19 pandemic, we present how Globus technologies are enabling the development of an open science platform for robust epidemic analysis, with the goal of collaborative, secure, distributed, on-demand, and fast time-to-solution analyses to support public health.
3. Without objects
we manipulate scalars, arrays, hashes...
$hash = {
key => 42,
another => {
one => 43,
deep => {
here => {
you => {
can => 'find me'
}
}
},
str => "Data value"
},
elts => [ 8, 25, 37, 64 ]
};
this lead to store data in /ugly/ hashes
4. Problems with this approach :
you need to know the "exact key" to use...
$hash->{key} = 42;
$hash->{anotherlevel}->{key} = "value";
$hash->{where}->{can}{be}{mykey} = { it => 's there' };
deep research into the code...
or need to dump huge hash
5. You can s/confound/mispell/ key name
somewhere
sub method {
my $h = shift;
$h->{key} = 42;
}
then later
...
$h->{keys}++ and $h->{kyes} = 51;
...
6. You cannot change the key name
or storage level
cannot become neither
$hash->{current_key} = 42;
nor
$hash->{updated_key} = 42;
$hash->{better}{key} = 42;
without updating
the full code !
7. You cannot control life cycle of an attribute :
sub somewhere {
...
$hash->{mykey} = 42 and additionnal_operation;
...
}
sub otherplace {
...
$hash->{mykey} = 43 and additionnal_operation;
...
}
•on create
•on update
•before, after, around
•hooks : innner, augment...
without objects
8. You would need an accessor
it should be the only single way
to access to this piece of data
sub mykey {
my ($self, $value) = @_;
if (defined $value) {
$self->{_mykey} = $value;
$self->additionnal_operation();
}
$self->{_mykey};
}
9. Writing documentation
=pod
=head attribute
Parameters : attribute value ( optional )
Description : attribute method can be used to read or update it !
Returns : current value
Usage :
# use as reader
my $read = $object->attribute();
# use as writter
$object->attribute($new_value);
=cut
sub attribute {
... some code there ( or not ! )
}
... is difficult
rather than
Please use $object->{level1}{level2} to access the expected value !
# at this time, and it could never change ?
10. What is an object ?
•functions
•data
Small piece of code
11. Why object / module ?
•code is organized
•Object is DRY, Lazy & Fun
•code is easier to read / share
•design & development can be dissociate
•easier to test
•provides fault containment
•reduce code maintenance
•simplify product evolution
•documentation is easier
12. Code organization
Object
|__ Human
| |___ Male
| |___ Female
|
|__ Transport
|___ Car
|___ Plane
|___ Bicycle
#!perl
package Object::Transport::Car;
13. DRY : Do not Repeat Yourself
package Document::Page;
sub create {
my $self = shift;
...
do_some_stuff; # inner();
...
}
package Document::Special;
extends 'Document::Page';
augment 'create' => sub {
my $self = shift;
$self->do_some_extra_stuff;
};
•inheritance help you factorize your code
•roles ( ~ interface )
14. Lazy
package Person;
use Moose; # or any other object module
has 'age' => ( is => 'rw', isa => 'Int', default => 42 );
package main;
my $p = Person->new() or Person->new(age => 64);
$current_age = $p->age();
$p->age($new_age);
•provide "new" method
•provide accessors
•parameters validation :
types, optional, default value...
15. Type checking
package Person;
use Try::Tiny;
use Moose;
use Moose::Util::TypeConstraints;
subtype 'Sex'
=> as 'Str'
=> where { $_ =~ m{^[mf]$}s };
has 'sex' => ( is => 'ro', isa => 'Sex', required => 1 );
has 'age' => ( is => 'rw', isa => 'Int', default => 42 );
my $person = Person->new( sex => 'm', age => 45 );
try {
Person->new( sex => 'unknown' );
} catch {
warn "Error has been detected";
};
16. Coercion
package My::Types::Date;
use Moose::Util::TypeConstraints; use DateTime; # ...
subtype 'MyType:Day' => as 'DateTime';
coerce 'MyType:Day' => from 'Str' => via {
/^d{4}d{2}d{2}$/ or croak "Unable to coerce '$_' into a valid date";
return DateTime::Format::DateParse->parse_datetime($_);
};
package Test::Coerce;
use Moose; use My::Types::Date;
has day => ( is => 'rw', isa => 'MyType:Day',
coerce => 1);
package main;
my $d1 = Test::Coerce->new(day => DateTime->now());
my $d2 = Test::Coerce->new(day => '20111130');
isa_ok $d2->day, 'DateTime', 'day is coerced to a DateTime object';
17. Which object library to choose ?
•Moose
•Mouse
•Moo
•Mo
•M
•...
•fields
•Object::Tiny(::XS)
•Class::XSAccessor
•write your own simple Object ?
and sometimes none
18. •the most advanced
•large ecosystem of extensions :
MooseX : validate, getopt, singleton,
types...
•can use advanced types and coercion
methods
•hooks : before, after, inner, augment...
•startup time
•memory usage
•dependencies...
Moose : the fat one !
fat but so good...
Advantages :
Disadvantages :
19. •same goal as Mouse : provide a Moose lighter
•but provide "as little as possible" : minimalist
Moo : the light one !
package Demo::Moo;
use Moo;
with 'Some::Role';
has bar => (
is => 'rw',
isa => sub { $_[0] =~ /^[+-]?d+$/ },
coerce => quote_sub q{ $_[0] + 1 unless $_[0] % 2 },
lazy => 1,
);
•can use only one role at a time
•not available : super, override, inner, augment
•no initializer
Start with Moo and if you need more, switch to Mouse / Moose
20. •use Class::XSAccessor
•fast, easy but extremely limited
•only implement getters
•do not provide setters
Object::Tiny[::XS] : The fast one !
package MyClass;
use Object::Tiny::XS qw{ list of attributes };
1;
package main;
my $object = MyClass->new( list => [ 42, 51 ], of => 'numbers' );
say join(',', @{$object->list}, $object->of);
eval { $object->attributes( 63 ); } or warn "Update value failed !";
21. Writing your own object module ?
package My::Object; # Inspired from Object::Tiny
sub import {
return unless shift eq __PACKAGE__;
my $pkg = caller;
@{"${pkg}::ISA"} = 'My::Object';
map {
my $method = "${pkg}::$_";
my $code = _get_accessor_for($_);
{ no strict 'refs'; *$method = $code; }
} @_;
return 1;
}
sub _get_accessor_for {
my ($key) = @_;
return unless caller eq __PACKAGE__; # Did I say private ?
defined $key and !ref $key and $key =~ /^[^Wd]w*z/s
or croak("Invalid key '$key'");
sub {
my ($self, $v) = @_;
$self->{$key} = $v if defined $v;
$self->{$key};
};
}
sub new {
my $class = shift;
bless { @_ }, $class;
}
# that’s all !
22. Using your own object module
package main;
# initialize your object using new method
my $elt = MyClass->new(list => [ 0, 1, 1, 2, 3, 5, 8, 13, 21, 34 ]);
# getter available
my $list = $elt->list;
# setter available
$elt->of('numbers');
package MyClass;
use My::Object qw{ list of attributes };
# that's all you need !
create a class
start playing with it
23. Extreme performance with Class::XSAccessor
package SuperFast;
use Class::XSAccessor
replace => 1,
constructor => 'new',
accessors => {
speed => 'speed',
},
predicates => {
has_speed => 'speed',
};
package main;
my $o = SuperFast->new(speed => 'flash');
is($o->speed, 'flash');
$o->speed('max') and say $o->speed;
is($o->speed, 'max');
•Fast read & write
•provide accessors, getters, setters and predicates
•use Devel::PPPort Perl Pollution Portability
24. Still want to keep using [better] hash ?
package Animal::Sounds;
use fields qw(cat dog bird);
sub new {
my Animal::Sounds $self = shift;
$self = fields::new($self) unless ref $self;
return $self;
}
package main;
my Animal::Sounds $sound = Animal::Sounds->new(); # typed lexical
$sound->{cat} = 'miaaooo'; # ok
$sound->{horse} = 'hiia'; # generates compile-time error
# No such class field "horse" in variable $sound of type Animal::Sounds
fields builtin provide compile-time class
Objects ( typed ) with named fields are
as compact and as fast arrays to access
25. fields limit
# extract from field.pm
*new = sub {
my $class = shift;
$class = ref $class if ref $class;
require Hash::Util;
my $self = bless {}, $class;
# The lock_keys() prototype won't work since we require Hash::Util :(
&Hash::Util::lock_keys(%$self, _accessible_keys($class));
# spent 6.00s making 20172 calls to Hash::Util::lock_keys, avg 297us/call
# spent 710ms making 20172 calls to fields::_accessible_keys, avg 35us/call
return $self;
}
be careful in production ( perl >= 5.009 )
Trick : mock *fields::new depending on current env
or switch to another object module
121 13.3ms
122 7.62ms
123 20.9ms
124 35.2ms
125
126
127 6.71s
128 61.6ms
129
•provides fast read access to attributes
•slow on object creation
26. Control hash life cycle
package main;
use Human;
use Test::More;
my $john = Human->new;
$john->{age} = 45;
is($john->{age}, 45, "nothing special");
$john->{age} = 123;
is($john->{age}, 99, "what happens there ?");
Still want to use hash ?
How is it possible ?
27. Use tie to hook
package Human;
sub TIESCALAR { die unless(ref $_[1] eq 'CODE'); my $cod=$_[1]; bless $cod, $_[0]; }
sub STORE { my $self = shift; $self->(@_); }
sub FETCH { shift->(); }
# many more available : DELETE, CLEAR, EXISTS, NEXTKEY...
sub new {
my $class = shift;
my $self = bless {}, $class;
my $age;
tie $self->{age}, __PACKAGE__, sub {
my ($value) = @_;
return $age unless defined $value;
warn "You looks too old" and $value = 99 if $value >= 100;
$age = $value;
return $age;
};
$self;
}
You can also tie array, hash...
28. When we should not choose object ?
"Premature optimization is the root of all evil"
Tony Hoare
•performance ?
•difficult to learn ?
•need to create too many objects ?
•do not like abstraction ?
29. Performance problems ?
1/ Analyze the problem origin
•waiting for database
•waiting for IO
•CPU usage
•Memory usage
•.... use Devel::NYTProf
2/ then apply the correct solution
•use parallel algorithm / poe
•use inline C / XS
•do not use object
•...
30. Object Benchmark
Moo : best average solution ( also consider Mouse )
Class::XSAccessor : performance
fields : when many update and few object creation needed
31. Common Errors & Tricks
•make Moose package immutable
no Moose;
__PACKAGE__->meta->make_immutable();
•object creation is time consuming :
use cache or singleton if possible
•use factory for abstraction
•fields use Hash::Util::Lock
# bad idea if too many objects creation
•be careful with Time syscall, try to share it :
my $now = Datetime->now();
•be careful with coercion
# do not try to do too much
~ /black mag/ic