The document discusses how the value or use of common items depends on who is holding them. It provides examples of how a basketball, baseball, tennis racket, rod, slingshot, fish and bread, and nails have much greater value or use when held by famous athletes, biblical figures, or God compared to an average person. The document encourages putting one's concerns, worries, fears, hopes, dreams, families, and relationships in God's hands, as what is done with them depends on whose hands they are in.
1) The document provides advice for students who need to study the night before an exam. It recommends assessing your workload and priorities, making a study plan with time estimates for each topic, organizing materials, using study guides and flashcards, asking friends for help, and getting enough sleep.
2) Specific study strategies are outlined, including using online resources, textbooks, class materials, asking teachers for help on confusing topics, and employing memory techniques.
3) Additional tips include moving while studying, writing notes by hand, taking breaks, eating well, thinking positively, and reviewing material again after the exam. The overall message is to plan ahead and study incrementally to avoid cramming.
Versatility! Effective Marketing! TeachStreet’s New Listings Editor! allows teachers to create comprehensive listings for their classes and services. The editor provides templates to include key information like a catchy title, descriptive tags, session details, pricing, location, dates and times, and student reviews. Teachers can easily add and edit listings by following the step-by-step process of filling out sections for the title, description, subject tags, sessions, photos and other components. This gives teachers organizational control and flexibility while also providing students with thorough information to find the right class.
Cascao London Cooperative Framework Agreeement NileAna Cascao
The document summarizes negotiations between countries in the Nile River Basin over a new water sharing agreement. It discusses the positions of upstream countries seeking more access to water versus downstream countries wanting to maintain the status quo. It also examines the use of ambiguity in negotiations, stakes involved for both sides, and external pressure from organizations to reach a deal over 10 years of discussions. However, negotiations have stalled due to disagreements over water security and no consensus has been reached on a new framework agreement.
Algortimos bio-inspirados para clustering y visualizacion de datos geoespacialesaskroll
This document discusses challenges in clustering and visualizing geospatial data. It notes that geospatial data has special characteristics that pose challenges, such as visualizing clusters in both geographic and feature spaces, handling relationships and boundaries at different scales, and the high dimensionality and volume of geospatial data sets. It also discusses representing similarities between georeferenced sites in both geographic space, concerned with surface features, and feature space, concerned with multidimensional similarities. Representing clusters found in feature space onto a 2D map is challenging as the clusters may not match geographic space clusters.
URL Best Practices | Rand Fishkin | SMX East NYC 2009Fabio Ricotta
The document summarizes findings from correlation data on URL best practices. It finds that shorter URLs, keywords in root domains, and fewer folders in URLs are more highly correlated with better search rankings. While keywords in subdomains, filenames, query strings, and paths provide some value, they are not as positively correlated as keywords in root domains. It also finds that HTTP URLs, WWW domains, and fewer characters in domain names are more frequently found in top search results.
A mother sacrifices greatly for her child from infancy through adulthood. She is supportive through illnesses, celebrates milestones like birthdays and starting school, buys clothes for her child instead of herself, proves her child's innocence to others, and gives her savings to buy a bicycle. As her child grows into independence with a job and marriage, the mother continues to show love and support, even as she grows older, having given all she had to her child. The document encourages appreciating all a mother sacrifices by giving her time and love in return.
The document discusses how the value or use of common items depends on who is holding them. It provides examples of how a basketball, baseball, tennis racket, rod, slingshot, fish and bread, and nails have much greater value or use when held by famous athletes, biblical figures, or God compared to an average person. The document encourages putting one's concerns, worries, fears, hopes, dreams, families, and relationships in God's hands, as what is done with them depends on whose hands they are in.
1) The document provides advice for students who need to study the night before an exam. It recommends assessing your workload and priorities, making a study plan with time estimates for each topic, organizing materials, using study guides and flashcards, asking friends for help, and getting enough sleep.
2) Specific study strategies are outlined, including using online resources, textbooks, class materials, asking teachers for help on confusing topics, and employing memory techniques.
3) Additional tips include moving while studying, writing notes by hand, taking breaks, eating well, thinking positively, and reviewing material again after the exam. The overall message is to plan ahead and study incrementally to avoid cramming.
Versatility! Effective Marketing! TeachStreet’s New Listings Editor! allows teachers to create comprehensive listings for their classes and services. The editor provides templates to include key information like a catchy title, descriptive tags, session details, pricing, location, dates and times, and student reviews. Teachers can easily add and edit listings by following the step-by-step process of filling out sections for the title, description, subject tags, sessions, photos and other components. This gives teachers organizational control and flexibility while also providing students with thorough information to find the right class.
Cascao London Cooperative Framework Agreeement NileAna Cascao
The document summarizes negotiations between countries in the Nile River Basin over a new water sharing agreement. It discusses the positions of upstream countries seeking more access to water versus downstream countries wanting to maintain the status quo. It also examines the use of ambiguity in negotiations, stakes involved for both sides, and external pressure from organizations to reach a deal over 10 years of discussions. However, negotiations have stalled due to disagreements over water security and no consensus has been reached on a new framework agreement.
Algortimos bio-inspirados para clustering y visualizacion de datos geoespacialesaskroll
This document discusses challenges in clustering and visualizing geospatial data. It notes that geospatial data has special characteristics that pose challenges, such as visualizing clusters in both geographic and feature spaces, handling relationships and boundaries at different scales, and the high dimensionality and volume of geospatial data sets. It also discusses representing similarities between georeferenced sites in both geographic space, concerned with surface features, and feature space, concerned with multidimensional similarities. Representing clusters found in feature space onto a 2D map is challenging as the clusters may not match geographic space clusters.
URL Best Practices | Rand Fishkin | SMX East NYC 2009Fabio Ricotta
The document summarizes findings from correlation data on URL best practices. It finds that shorter URLs, keywords in root domains, and fewer folders in URLs are more highly correlated with better search rankings. While keywords in subdomains, filenames, query strings, and paths provide some value, they are not as positively correlated as keywords in root domains. It also finds that HTTP URLs, WWW domains, and fewer characters in domain names are more frequently found in top search results.
A mother sacrifices greatly for her child from infancy through adulthood. She is supportive through illnesses, celebrates milestones like birthdays and starting school, buys clothes for her child instead of herself, proves her child's innocence to others, and gives her savings to buy a bicycle. As her child grows into independence with a job and marriage, the mother continues to show love and support, even as she grows older, having given all she had to her child. The document encourages appreciating all a mother sacrifices by giving her time and love in return.
If the world's population was represented by a village of 100 people, 57 would be Asian, 21 European, 14 American, and 8 African. There would be 52 women and 48 men, with 30 Caucasians and 70 non-Caucasians. 30 would be Christian and 70 non-Christian. 6 people would possess 59% of the wealth and be from the US, while 80 would live in poverty and 70 would be illiterate. 50 would suffer from hunger/malnutrition, 1 would be dying, 1 being born, 1 owning a computer, and 1 having a university degree. The document emphasizes that most people in the world face challenges like poverty, hunger, lack of access to education or technology, and risks
This document provides an overview of key Perl concepts including scalars, arrays, hashes, I/O, operators, and control structures. It discusses scalar data types like strings and numbers. It also covers arrays, hashes, and common functions for each. The document outlines I/O with the console, files, and handles. It briefly summarizes operators and precedence. Finally, it discusses control structures like if/else, loops, and modifiers.
This document provides tips for negotiating a rental agreement without just offering more money. It suggests highlighting other desirable attributes like being tidy, considerate of neighbors, and able to do garden maintenance. These non-monetary factors are as or more important to landlords. The document also advises bringing references, photos, and other evidence to validate claims. In job interviews, a similar approach can make one stand out over candidates only meeting basic qualifications. Non-monetary qualities like hobbies, language skills, and volunteer work should be emphasized.
Cascao Addis Ababa Knowledge For Water Equity Nile Basin 2006Ana Cascao
1. There is a knowledge gap between upstream and downstream countries in the Nile River Basin regarding water expertise, learning, and decision making which can impact negotiations.
2. Countries have accumulated water knowledge over time through higher education, research, and international organizations, but there are differences in levels of expertise between countries like Egypt and Ethiopia.
3. Water knowledge and numbers are important for negotiations and bargaining power over water allocations, but knowledge also needs to be integrated across disciplines and include social and environmental perspectives to work towards more equitable outcomes.
This document contains the calls for a game of bingo with random numbers being called out. Numbers from 1 to 12 are called in a seemingly random order with some numbers being called multiple times. Basic math equations are provided at the end to test the reader's addition, subtraction and multiplication skills.
The document discusses how search tools have evolved to meet changing information needs. It notes that while Google is a popular search engine, understanding different types of search tools is important. The document categorizes search engines based on what they index and how queries are processed. It also evaluates search engine performance using metrics like recall and precision. Finally, it deconstructs the search experience and considers factors of various search engines like Google.
You belong here and you can be successfulcolwilliamson
This document summarizes a seminar for new students about transitioning to a new school environment. A 12th grade student and faculty member will share their experiences adjusting to the new school culture and offer suggestions. They will discuss that there is no shame in getting a tutor, developing a positive attitude for studying, and that it gets easier over time. Students will have a chance to ask questions. The seminar also includes an activity where students rate their comfort and challenge levels in classes to identify areas to improve. Resources for support like advisors, counselors, and tutoring are outlined.
Connie Duque has over 15 years of experience in marketing and product management. She has worked for several companies in roles such as Product Development Manager, Brand Manager, and Marketing Manager. Notable accomplishments include developing a new category of water filtration products that generated $20 million in revenue, expanding product lines, and centralizing brand messaging. In her spare time, she enjoys yoga, pilates, and running.
This document summarizes 7 of the most beautiful oases from around the world. It describes the Ubari Oasis in Libya located between sand dunes and lakes that is home to the Tuareg people. It also discusses the tiny oasis settlement of Huacachina in Peru with its lagoon and palm trees that serves as a resort. Additionally, it mentions the Ein Gedi oasis along the Dead Sea in Israel that has been inhabited since ancient times.
Posting a video on TeachStreet involves signing in, writing a new article, clicking "Add a video/media" and pasting the embed code. The video and article will help promote your business and expertise on a wider audience. Be sure to include a great title, details about the video, subject categories and tags before publishing the article.
From Idea to Exit, the story of our startupNatalie Downe
Natalie launched the first version of Lanyrd.com with a co-founder and her husband Simon, while on honeymoon in Casablanca. As the site took off, they realized their side project was destined to become something much bigger.
This talk will tell the story of Lanyrd from a two-week proof of concept to a fully-fledged startup, the lessons learned along the way about building and launching a product, running a company, raising investment and the entrepreneurship journey. This is the talk she wished she heard before getting started!
Natalie Downe co-founded Lanyrd, a YCombinator backed startup (W11) that helps companies and individuals get more out of conferences and professional events. She is an experienced product designer, product manager and front-end web engineer. Lanyrd was acquired by Eventbrite in August 2013 and she is now the Director of Frontend Engineering at Eventbrite.
The document discusses keeping God first in all areas of life, not just church on Sundays. It encourages the reader to not be ashamed of God and to pass the message on to others if they truly love God. It asserts that without God, one is nothing, but with God one can do all things through Christ.
The document discusses the value of true friendship. It defines a friend as a confidant, listener, and shoulder to cry on. A friend is someone you share your deepest secrets and experiences with, even more so than family. True friendship is a unique bond that can withstand disagreements and lasts through challenges. It is a foundation necessary for life. The document expresses gratitude to the reader for their friendship.
This document contains several quotes and sayings about the value of true friendship. It discusses how real friends are there for each other through both good and bad times, and how true friendship is only fully appreciated once it has been lost. Friends listen to and support each other, help each other through challenges, and take pieces of each other with them as they journey through life.
If the world's population was represented by a village of 100 people, 57 would be Asian, 21 European, 14 American, and 8 African. There would be 52 women and 48 men, with 30 Caucasians and 70 non-Caucasians. 30 would be Christian and 70 non-Christian. 6 people would possess 59% of the wealth and be from the US, while 80 would live in poverty and 70 would be illiterate. 50 would suffer from hunger/malnutrition, 1 would be dying, 1 being born, 1 owning a computer, and 1 having a university degree. The document emphasizes that most people in the world face challenges like poverty, hunger, lack of access to education or technology, and risks
This document provides an overview of key Perl concepts including scalars, arrays, hashes, I/O, operators, and control structures. It discusses scalar data types like strings and numbers. It also covers arrays, hashes, and common functions for each. The document outlines I/O with the console, files, and handles. It briefly summarizes operators and precedence. Finally, it discusses control structures like if/else, loops, and modifiers.
This document provides tips for negotiating a rental agreement without just offering more money. It suggests highlighting other desirable attributes like being tidy, considerate of neighbors, and able to do garden maintenance. These non-monetary factors are as or more important to landlords. The document also advises bringing references, photos, and other evidence to validate claims. In job interviews, a similar approach can make one stand out over candidates only meeting basic qualifications. Non-monetary qualities like hobbies, language skills, and volunteer work should be emphasized.
Cascao Addis Ababa Knowledge For Water Equity Nile Basin 2006Ana Cascao
1. There is a knowledge gap between upstream and downstream countries in the Nile River Basin regarding water expertise, learning, and decision making which can impact negotiations.
2. Countries have accumulated water knowledge over time through higher education, research, and international organizations, but there are differences in levels of expertise between countries like Egypt and Ethiopia.
3. Water knowledge and numbers are important for negotiations and bargaining power over water allocations, but knowledge also needs to be integrated across disciplines and include social and environmental perspectives to work towards more equitable outcomes.
This document contains the calls for a game of bingo with random numbers being called out. Numbers from 1 to 12 are called in a seemingly random order with some numbers being called multiple times. Basic math equations are provided at the end to test the reader's addition, subtraction and multiplication skills.
The document discusses how search tools have evolved to meet changing information needs. It notes that while Google is a popular search engine, understanding different types of search tools is important. The document categorizes search engines based on what they index and how queries are processed. It also evaluates search engine performance using metrics like recall and precision. Finally, it deconstructs the search experience and considers factors of various search engines like Google.
You belong here and you can be successfulcolwilliamson
This document summarizes a seminar for new students about transitioning to a new school environment. A 12th grade student and faculty member will share their experiences adjusting to the new school culture and offer suggestions. They will discuss that there is no shame in getting a tutor, developing a positive attitude for studying, and that it gets easier over time. Students will have a chance to ask questions. The seminar also includes an activity where students rate their comfort and challenge levels in classes to identify areas to improve. Resources for support like advisors, counselors, and tutoring are outlined.
Connie Duque has over 15 years of experience in marketing and product management. She has worked for several companies in roles such as Product Development Manager, Brand Manager, and Marketing Manager. Notable accomplishments include developing a new category of water filtration products that generated $20 million in revenue, expanding product lines, and centralizing brand messaging. In her spare time, she enjoys yoga, pilates, and running.
This document summarizes 7 of the most beautiful oases from around the world. It describes the Ubari Oasis in Libya located between sand dunes and lakes that is home to the Tuareg people. It also discusses the tiny oasis settlement of Huacachina in Peru with its lagoon and palm trees that serves as a resort. Additionally, it mentions the Ein Gedi oasis along the Dead Sea in Israel that has been inhabited since ancient times.
Posting a video on TeachStreet involves signing in, writing a new article, clicking "Add a video/media" and pasting the embed code. The video and article will help promote your business and expertise on a wider audience. Be sure to include a great title, details about the video, subject categories and tags before publishing the article.
From Idea to Exit, the story of our startupNatalie Downe
Natalie launched the first version of Lanyrd.com with a co-founder and her husband Simon, while on honeymoon in Casablanca. As the site took off, they realized their side project was destined to become something much bigger.
This talk will tell the story of Lanyrd from a two-week proof of concept to a fully-fledged startup, the lessons learned along the way about building and launching a product, running a company, raising investment and the entrepreneurship journey. This is the talk she wished she heard before getting started!
Natalie Downe co-founded Lanyrd, a YCombinator backed startup (W11) that helps companies and individuals get more out of conferences and professional events. She is an experienced product designer, product manager and front-end web engineer. Lanyrd was acquired by Eventbrite in August 2013 and she is now the Director of Frontend Engineering at Eventbrite.
The document discusses keeping God first in all areas of life, not just church on Sundays. It encourages the reader to not be ashamed of God and to pass the message on to others if they truly love God. It asserts that without God, one is nothing, but with God one can do all things through Christ.
The document discusses the value of true friendship. It defines a friend as a confidant, listener, and shoulder to cry on. A friend is someone you share your deepest secrets and experiences with, even more so than family. True friendship is a unique bond that can withstand disagreements and lasts through challenges. It is a foundation necessary for life. The document expresses gratitude to the reader for their friendship.
This document contains several quotes and sayings about the value of true friendship. It discusses how real friends are there for each other through both good and bad times, and how true friendship is only fully appreciated once it has been lost. Friends listen to and support each other, help each other through challenges, and take pieces of each other with them as they journey through life.
Equips cibernètics, realitat o ficció? (Jornada TIC UPC 2017)Alex Muntada Duran
La proliferació d'agents intel·ligents, també coneguts com "bots", en diferents plataformes digitals posa damunt la taula la possibilitat que aquests esdevinguin un membre més de l'equip, amb responsabilitats i amb competència per dur a terme determinades tasques de forma autònoma i aportant feedback.
My talk about REST in Barcelona Software Craftsmanship Meetup on May 19, 2014.
http://www.meetup.com/Barcelona-Software-Craftsmanship/events/173793192/
This document provides an introduction to the Perl programming language. It discusses the history and creation of Perl in 1987 by Larry Wall. It also covers the differences between Perl 5 and Perl 6, and provides information about Barcelona.pm which is a local Perl user group that teaches Perl courses on topics like data and operators, data structures, files and directories, regular expressions, and object-oriented programming. Wi-Fi connection details are also listed for attending their events.
This document summarizes tools for modern Perl development including App::perlbrew for managing multiple Perl installations, App::cpanminus for installing modules, and Dist::Zilla for building and releasing distributions. It provides instructions for installing each tool and using them to install Perls, modules, and develop and release distributions.
This document discusses various methods for packaging and testing Perl modules for Ubuntu, including the classic Perl way, the quick cpan way, and the Debian/Ubuntu way using dh-make-perl. It also covers creating a Personal Package Archive (PPA) on Launchpad to distribute packages and use bzr-buildpackage for version control. Testing with pbuilder is recommended to build packages in a clean, controlled environment.
5. Capítol 1
Sistema d’objectes de Perl 5
La base del sistema d’objectes són els mòduls (o paquets).
1.1 Mòduls
Com en qualsevol altre llenguatge permeten:
• reutilització
• separació
• encapsulament
• …
1.1.1 Espai de noms
use Foo ;
say $INC { ' Foo . pm '};
# / path / to / lib / Foo . pm
use Foo :: Bar ;
say $INC { ' Foo / Bar . pm '};
# / path / to / lib / Foo / Bar . pm
1.1.2 On es busquen
our @INC ;
use lib '/ path / to / lib ';
$ export PERL5LIB =/ path / to / lib
$ perl -V
1
6. Capítol 1 Sistema d’objectes de Perl 5 Alex Muntada Curs de Perl
1.1.3 Quin aspecte tenen
Abans es feien d’aquesta manera:
package HelloWorld ;
# our $VERSION = '1.00 ';
use vars qw ( $VERSION );
$VERSION = ' 1.00 ';
# ...
1;
A partir de Perl 5.14 ja es poden fer d’aquesta altra:
use 5.014;
use Modern :: Perl ' 2012 ';
package HelloWorld 1.00 {
# ...
}
1;
1.1.4 Com s’utilitzen
use 5.014;
use Modern :: Perl ' 2012 ';
package HelloWorld {
sub hello {
return " Hello , world !";
}
}
# package main {
say HelloWorld :: hello ();
# }
Llistat 1.1: HelloWorld-hello.pl
1.1.5 Com es defineixen
Aquesta és la definició d’un mòdul més complex:
use 5.014;
use Modern :: Perl ' 2012 ';
package HelloWorld 1.00 {
use Exporter qw ( import );
our @EXPORT = qw ( hello );
our @EXPORT_OK = qw ( japh );
2
7. Alex Muntada Curs de Perl Secció 1.1 Mòduls
sub hello {
return " Hello , world !";
}
sub japh {
return " Just another Perl hacker ,";
}
}
1;
Llistat 1.2: lib/1.00/HelloWorld.pm
1.1.6 Crida a les funcions del mòdul
use 5.014;
use Modern :: Perl ' 2012 ';
use lib ' lib /1.00 ';
use HelloWorld 1.00;
say hello ();
say HelloWorld :: japh ();
Llistat 1.3: hello1.pl
1.1.7 Importació de símbols
use 5.014;
use Modern :: Perl ' 2012 ';
use lib ' lib /1.00 ';
use HelloWorld 1.00 qw ( japh );
# say hello (); => FAIL
say japh ();
Llistat 1.4: hello2.pl
1.1.8 require vs. use
require…
• s’avalua en temps d’execució,
• un sol cop,
• inclou el resultat al context actual.
use fa el mateix però…
• s’avalua en temps de compilació,
3
8. Capítol 1 Sistema d’objectes de Perl 5 Alex Muntada Curs de Perl
• només admet barewords com a nom del mòdul,
• sense eval no es poden utilitzar variables pel nom,
• permet afegir una restricció de versió mínima del mòdul.
1.1.9 use vs. no
# use Module ;
BEGIN { require Module ; Module -> import (); }
# use Module ();
BEGIN { require Module ; }
# use Module LIST ;
BEGIN { require Module ; Module -> import ( LIST ); }
# no Module LIST ;
BEGIN { require Module ; Module -> unimport ( LIST ); }
1.2 Classes, mètodes i atributs
El mateix exemple d’abans…
use 5.014;
use Modern :: Perl ' 2012 ';
package HelloWorld 1.00 {
use Exporter qw ( import );
our @EXPORT = qw ( hello );
our @EXPORT_OK = qw ( japh );
sub hello {
return " Hello , world !";
}
sub japh {
return " Just another Perl hacker ,";
}
}
1;
Llistat 1.5: lib/1.00/HelloWorld.pm
1.2.1 Constructors, atributs, getters i setters
Els objectes són en realitat referències:
use 5.014;
use Modern :: Perl ' 2012 ';
package HelloWorld 1.01 {
4
9. Alex Muntada Curs de Perl Secció 1.2 Classes, mètodes i atributs
use Carp qw ( croak );
sub new {
my ( $class , % args ) = @_ ;
my $obj = {
hello => " Hello , world ! " ,
japh => " Just another Perl hacker , " ,
% args ,
};
return bless $obj , $class ;
}
sub hello {
my $self = shift ;
return @_ ? $self -> set_hello ( @_ ) : $self - > get_hello ();
}
sub japh {
my $self = shift ;
return @_ ? $self -> set_japh ( @_ ) : $self - > get_japh ();
}
sub AUTOLOAD {
my $self = shift ;
my @args = @_ ;
our $AUTOLOAD ;
my ( $method ) = $AUTOLOAD =~ /::( w +) $ /;
if ( $method =~ /^ get_ ( w +)/ && exists $self - >{ $1 } ) {
return $self - >{ $1 };
}
elsif ( $method =~ /^ set_ ( w +)/ && exists $self - >{ $1 } ) {
my $new_value = $args [0];
my $old_value = $self - >{ $1 };
$self - >{ $1 } = $new_value ;
return $new_value ;
}
else {
croak " Bad method name < $method >! ";
}
}
sub DESTROY { }
}
1;
Llistat 1.6: lib/1.01/HelloWorld.pm
5
10. Capítol 1 Sistema d’objectes de Perl 5 Alex Muntada Curs de Perl
1.2.2 Instàncies
use 5.014;
use Modern :: Perl ' 2012 ';
use lib ' lib /1.01 ';
use HelloWorld 1.01;
my $h = HelloWorld -> new ();
say $h -> hello ();
say $h -> japh ();
my $j = HelloWorld -> new ( hello => ' JAPH ! ' );
say $j -> hello ();
Llistat 1.7: hello3.pl
1.2.3 Accessors
use 5.014;
use Modern :: Perl ' 2012 ';
use lib ' lib /1.01 ';
use HelloWorld 1.01;
my $j = HelloWorld -> new ();
# $j - > hello (); => OK
my $old_hello = $j -> get_hello ();
$j -> set_hello ( $j -> get_japh () );
say $old_hello ;
say $j -> get_hello ();
# say $j -> get_foobar (); => FAIL
Llistat 1.8: hello4.pl
1.3 Herència
use 5.014;
use Modern :: Perl ' 2012 ';
package Baz {
use parent qw ( Foo Bar );
}
package Baz {
BEGIN {
require Foo ;
require Bar ;
push our @ISA , qw ( Foo Bar );
}
6
13. Capítol 2
Moose
2.1 Introducció
• Construït damunt del sistema d’objectes de Perl 5.
• Pren característiques d’altres llenguatges com Smalltalk, Common Lisp i Perl 6.
• La forma més moderna de programar amb objectes en Perl modern.
• Té sabors alternatius: Mouse, Moo, Mo.
2.1.1 Classes, mètodes i atributs
use 5.014;
use Modern :: Perl ' 2012 ';
package Pet {
use Moose ;
has ' name ' => (
is => 'ro ',
isa => ' Str ',
);
}
package Cat {
use Moose ;
extends ' Pet ';
has ' diet ' => (
is => 'rw ',
isa => ' Str ',
);
has ' birth_year ' => (
is => 'ro ',
isa => ' Int ',
default => sub { ( localtime )[5] + 1900 } ,
);
9
14. Capítol 2 Moose Alex Muntada Curs de Perl
sub meow {
say " Meow !";
}
sub age {
my $self = shift ;
my $year = ( localtime )[5] + 1900;
return $year - $self -> birth_year ;
}
}
package main {
my $fat = Cat -> new ( name => ' Fatty ' , age => 8 , diet = > ' Sea Treats ' );
say $fat -> name , ' eats ', $fat -> diet ;
$fat -> diet ( ' Low Sodium Kitty Lo Mein ' );
say $fat -> name , ' eats ', $fat -> diet ;
}
Llistat 2.1: cat.pl
2.1.2 Hello, world!
use 5.014;
use Modern :: Perl ' 2012 ';
package HelloWorld 2.00 {
use Moose ;
has ' hello ' => (
is => 'rw ',
isa => ' Str ',
default => ' Hello , world ! ',
);
has ' japh ' => (
is => 'ro ',
isa => ' Str ',
default => ' Just another Perl hacker , ' ,
);
}
1;
Llistat 2.2: lib/2.00/HelloWorld.pm
use 5.014;
use Modern :: Perl ' 2012 ';
use lib ' lib /2.00 ';
use HelloWorld 2.00;
my $h = HelloWorld -> new ();
say $h -> hello ();
10
15. Alex Muntada Curs de Perl Secció 2.1 Introducció
$h -> hello ( ' hello ');
say $h -> hello ();
say $h -> japh ();
# $h - > japh (' japh '); => FAIL
my $j = HelloWorld -> new ( hello => ' JAPH ! ' );
say $j -> hello ();
Llistat 2.3: hello5.pl
2.1.3 Hello, world! accessible
use 5.014;
use Modern :: Perl ' 2012 ';
package HelloWorld 2.01 {
use Moose ;
has ' hello ' => (
is => 'rw ',
isa => ' Str ',
default => ' Hello , world ! ',
reader => ' get_hello ',
writer => ' set_hello ',
);
has ' japh ' => (
is => 'ro ',
isa => ' Str ',
default => ' Just another Perl hacker , ' ,
reader => ' get_japh ' ,
writer => ' set_japh ' ,
);
}
1;
Llistat 2.4: lib/2.01/HelloWorld.pm
use 5.014;
use Modern :: Perl ' 2012 ';
use lib ' lib /2.01 ';
use HelloWorld 2.01;
my $j = HelloWorld -> new ();
# $j - > hello (); => FAIL
my $old_hello = $j -> get_hello ();
$j -> set_hello ( $j -> get_japh () );
say $old_hello ;
say $j -> get_hello ();
# say $j -> get_foobar (); => FAIL
11
16. Capítol 2 Moose Alex Muntada Curs de Perl
Llistat 2.5: hello6.pl
2.2 Modificadors de mètodes
2.2.1 before, after, around
package Cat {
# ...
before ' age ' => sub {
my $self = shift ;
die " cannot ask for " . $self -> name . " age "
unless $self -> doesnt_care ;
};
after ' age ' => sub {
warn " too late to care n" ;
};
}
package HelloWorld {
# ...
around ' hello ' => sub {
my $orig = shift ;
my $self = shift ;
my $text = join q{ :: }, @_ ;
return $self -> $orig ( $text );
};
}
2.2.2 super, override
package CheaterKitty {
# ...
extends ' Cat ';
override ' age ' => sub {
my $self = shift ;
my $age = super ();
$age /= 2
if $age > 1;
return $age ;
};
}
12
17. Alex Muntada Curs de Perl Secció 2.3 Subtipus i coercions
2.2.3 inner, augment
use 5.014;
use Modern :: Perl ' 2012 ';
package Document {
use Moose ;
sub as_xml {
my $self = shift ;
my $xml = " < document >";
$xml .= inner ();
$xml .= " </ document >";
return $xml ;
}
}
package Report {
use Moose ;
extends ' Document ';
augment ' as_xml ' => sub {
my $self = shift ;
return " < report > This is a report </ report > " ;
};
}
package main {
my $report = Report -> new ();
say $report -> as_xml ();
}
Llistat 2.6: report.pl
2.3 Subtipus i coercions
use 5.014;
use Modern :: Perl ' 2012 ';
package Foo {
use Moose ;
use Moose :: Util :: TypeConstraints ;
use Moose :: Autobox ;
subtype ' ArrayRefOfPositiveInts ' ,
as ' ArrayRef [ Int ] ',
message { " The array you provided has a negative number " } ,
where {
my @array = @$_ ;
my $positive = 1;
13
18. Capítol 2 Moose Alex Muntada Curs de Perl
for my $next ( @array ) {
$positive &&= ( $next >= 0 ) or last ;
}
return $positive ;
};
coerce ' ArrayRefOfPositiveInts ' ,
from ' Int ',
via { [ $_ ] };
has ' sizes ' => (
is => 'ro ',
isa => ' ArrayRefOfPositiveInts ',
coerce => 1,
);
}
package main {
Foo -> new ( sizes => 42 );
# Foo -> new ( sizes => [ 42 , -42 ] ); => FAIL
}
Llistat 2.7: foo.pl
2.4 Rols i trets
2.4.1 Per què?
• Objectes: què és el sistema.
– Com són els objectes.
– El model de dades és estable.
– Habitualment és necessari documentar-lo.
• Rols: què fa el sistema.
– La lògica de negoci és canviable en el temps.
– Facilita la creació de tests.
– Eviten documentar els algorismes, el codi és la documentació.
– Els trets a Moose són rols composats en temps d’execució.
• Vistes: interacció amb els usuaris.
– Diferents dispositius tenen entrades i sortides diferents.
– Aspectes diversos: presentació, blog, llibre, etc.
– Formats de sortida: HTML, text, ODT, PDF, etc.
14
19. Alex Muntada Curs de Perl Secció 2.4 Rols i trets
2.4.2 Composició de rols
use 5.014;
use Modern :: Perl ' 2012 ';
package HelloWorld 2.02 {
use Moose :: Role ;
requires qw ( hello );
has ' japh ' => (
is => 'ro ',
isa => ' Str ',
default => ' Just another Perl hacker , ' ,
);
sub japh_hello {
my $self = shift ;
return $self -> japh . ' ' . $self -> hello . '! ';
}
}
1;
Llistat 2.8: lib/2.02/HelloWorld.pm
use 5.014;
use Modern :: Perl ' 2012 ';
package Pet 2.02 {
use Moose ;
has ' name ' => (
is => 'ro ',
isa => ' Str ',
);
}
1;
Llistat 2.9: lib/2.02/Pet.pm
use 5.014;
use Modern :: Perl ' 2012 ';
package Cat 2.02 {
use Moose ;
extends ' Pet ';
has ' diet ' => (
is => 'rw ',
isa => ' Str ',
);
has ' birth_year ' => (
15
20. Capítol 2 Moose Alex Muntada Curs de Perl
is => 'ro ',
isa => ' Int ',
default => sub { ( localtime )[5] + 1900 } ,
);
has ' hello ' => (
is => 'rw ',
isa => ' Str ',
lazy => 1,
default => sub { " hello " . shift -> name } ,
);
with ' HelloWorld ';
sub meow {
say " Meow !";
}
sub age {
my $self = shift ;
my $year = ( localtime )[5] + 1900;
return $year - $self -> birth_year ;
}
}
1;
Llistat 2.10: lib/2.02/Cat.pm
use 5.014;
use Modern :: Perl ' 2012 ';
use lib ' lib /2.02 ';
use Cat 2.02;
my $fat = Cat -> new ( name => ' Kitty ', age = > 8 , diet = > ' Sea Treats ' );
say $fat -> japh_hello ()
if $fat -> DOES ( ' HelloWorld ');
Llistat 2.11: hello7.pl
2.5 Delegació
Importa mètodes d’un atribut sense crear una relació d’herència o composició de rols:
package Website {
use Moose ;
has ' uri ' => (
is => 'ro ',
isa => ' URI ',
handles => [ qw ( host path )] ,
);
}
16
21. Alex Muntada Curs de Perl Secció 2.6 Constructors i destructors
2.6 Constructors i destructors
Compte! No definiu cap mètode new ni DESTROY. Disposeu d’aquests mecanismes:
• BUILDARGS abans de crear l’objecte.
• BUILD després de crear l’objecte.
• DEMOLISH durant la destrucció de l’objecte.
2.7 Protocol de meta-objectes i immutabilitat
Tota aquest màgia és possible gràcies al MOP:
my $meta = User -> meta ();
for my $attribute ( $meta -> get_all_attributes ) {
print $attribute -> name () , "n" ;
if ( $attribute -> has_type_constraint ) {
print " type : " , $attribute -> type_constraint - > name , " n " ;
}
}
for my $method ( $meta -> get_all_methods ) {
print $method -> name , "n";
}
Per optimitzar l’execució i per evitar que una classe canviï:
__PACKAGE__ -> meta -> make_immutable ;
2.8 Extensions de Moose
Algunes de les extensions recomanades a Moose::Manual::MooseX:
• Moose::Autobox
• MooseX::StrictConstructor
• MooseX::Params::Validate
• MooseX::Getopt
• MooseX::Singleton
Altres extensions interessants:
• MooseX::Declare
• MooseX::ClassAttribute
• MooseX::Daemonize
• MooseX::Role::Parameterized
17
22. Capítol 2 Moose Alex Muntada Curs de Perl
• MooseX::SemiAffordanceAccessor
• MooseX::NonMoose
18
23. Capítol 3
Pràctica
A partir de la classe HelloWorld, dissenyeu un sistema de presentació de diapositives que
pugui generar sortida en diferents formats.
• Heu d’utilitzar Moose.
• Separeu el què és el sistema del què fa amb Moose::Role.
• Utilitzeu els patrons Model-Vista-Controlador (MVC) o Data-Context-Interaction (DCI).
• El sistema ha de generar com a mínim una versió en HTML.
• Opcionalment pot generar versions en ODF, PDF, etc.
3.1 TMTOWTDI
Debat sobre les propostes:
• Punts forts i punts febles.
• Alternatives.
3.2 Solució senzilla
Una classe Doc que composa el rol HTML.
3.2.1 Composició estàtica de rols
use 5.014;
use Modern :: Perl ' 2012 ';
package HTML 3.00 {
use Moose :: Role ;
requires qw ( title body author );
sub print_html {
my $self = shift ;
19
24. Capítol 3 Pràctica Alex Muntada Curs de Perl
say " < title >" . $self -> title . " </ title >" ;
say " < head meta =" author " content =" " . $self - > author . " "/ > " ;
say " <body >" . $self -> body . " </ body >" ;
}
}
1;
Llistat 3.1: lib/3.00/HTML.pm
use 5.014;
use Modern :: Perl ' 2012 ';
package Doc 3.00 {
use Moose ;
has ' title ', is => 'ro ', isa => ' Str ';
has ' body ', is => 'ro ', isa => ' Str ';
has ' tag_list ', is => 'ro ', isa = > ' ArrayRef [ Str ] ';
has ' author ', is => 'ro ', isa = > ' Str ';
with ' HTML ';
}
1;
Llistat 3.2: lib/3.00/Doc.pm
use 5.014;
use Modern :: Perl ' 2012 ';
use lib ' lib /3.00 ';
use Doc 3.00;
my $r = Doc -> new ( title => 'T ', body = > 'B ', author = > 'A ' );
$r -> print_html
if $r -> DOES ( ' HTML ');
Llistat 3.3: doc1.pl
3.2.2 Composició dinàmica de rols
use 5.014;
use Modern :: Perl ' 2012 ';
package HTML 3.01 {
use Moose :: Role ;
requires qw ( title body author );
sub print_html {
my $self = shift ;
say " < title >" . $self -> title . " </ title >" ;
20
25. Alex Muntada Curs de Perl Secció 3.2 Solució senzilla
say " < head meta =" author " content =" " . $self - > author . " "/ > " ;
say " <body >" . $self -> body . " </ body >" ;
}
}
1;
Llistat 3.4: lib/3.01/HTML.pm
use 5.014;
use Modern :: Perl ' 2012 ';
package Doc 3.01 {
use Moose ;
has ' title ', is => 'ro ', isa => ' Str ';
has ' body ', is => 'ro ', isa => ' Str ';
has ' tag_list ', is => 'ro ', isa = > ' ArrayRef [ Str ] ';
has ' author ', is => 'ro ', isa = > ' Str ';
}
1;
Llistat 3.5: lib/3.01/Doc.pm
use 5.014;
use Modern :: Perl ' 2012 ';
use lib ' lib /3.01 ';
use Doc 3.01;
use Moose :: Util qw ( apply_all_roles );
my $r = Doc -> new ( title => 'T ', body = > 'B ', author = > 'A ' );
apply_all_roles ( $r , ' HTML ' );
$r -> print_html if $r -> DOES ( ' HTML ' );
Llistat 3.6: doc2.pl
21