Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add content to new concepts #675

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions concepts/booleans-and-conditionals/about.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# About

## Booleans

Boolean values exist in Perl, however they are seldom used explicitly.
They typically come as the result of a comparison operation, e.g, `2 > 1` or `'foo' eq 'bar'`, or negation, e.g., `!0`.

`1` and `0` are commonly used to represent true and false in boolean contexts.
With `use v5.40` or newer, the functions `true` and `false` are included to provide explicit boolean values.

The following are considered false in Perl:

```perl
0; # The number 0.
'0'; # A single 0 in a string.
''; # An empty string.
(); # An empty list.
undef;
```
19 changes: 19 additions & 0 deletions concepts/booleans-and-conditionals/introduction.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Introduction

## Booleans

Boolean values exist in Perl, however they are seldom used explicitly.
They typically come as the result of a comparison operation, e.g, `2 > 1` or `'foo' eq 'bar'`, or negation, e.g., `!0`.

`1` and `0` are commonly used to represent true and false in boolean contexts.
With `use v5.40` or newer, the functions `true` and `false` are included to provide explicit boolean values.

The following are considered false in Perl:

```perl
0; # The number 0.
'0'; # A single 0 in a string.
''; # An empty string.
(); # An empty list.
undef;
```
54 changes: 54 additions & 0 deletions concepts/object-orientation/about.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# About

## Classes

Class-based object orientation is a paradigm often used in Perl.
Traditionally, classes in Perl are created by using `bless` to associate a reference with a package.

```perl
package Foo;

sub new ($class, %args) {
return bless {%args{bar}}, $class;
}

sub bar ($self) {
return $self->{bar};
}
```

Perl `v5.38` introduced the `class` keyword which brings additional OOP features to core Perl.

```perl
use feature qw<class>;

class Foo;

field $bar :param;

method bar () {
return $bar;
}
```

Additionally, Perl has numerous modules available on CPAN implementing OOP features.
Among the most well known are `Moo` and `Moose`.

```perl
package Foo;

use Moo;

has bar => (is => 'ro');
```

The arrow operator (`->`) is used to call methods on class names and objects.
All of the above can be used as follows:

```perl
# Object creation
my $object = Foo->new(bar => 1);

# Method call
say $object->bar;
```
54 changes: 54 additions & 0 deletions concepts/object-orientation/introduction.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Introduction

## Classes

Class-based object orientation is a paradigm often used in Perl.
Traditionally, classes in Perl are created by using `bless` to associate a reference with a package.

```perl
package Foo;

sub new ($class, %args) {
return bless {%args{bar}}, $class;
}

sub bar ($self) {
return $self->{bar};
}
```

Perl `v5.38` introduced the `class` keyword which brings additional OOP features to core Perl.

```perl
use feature qw<class>;

class Foo;

field $bar :param;

method bar () {
return $bar;
}
```

Additionally, Perl has numerous modules available on CPAN implementing OOP features.
Among the most well known are `Moo` and `Moose`.

```perl
package Foo;

use Moo;

has bar => (is => 'ro');
```

The arrow operator (`->`) is used to call methods on class names and objects.
All of the above can be used as follows:

```perl
# Object creation
my $object = Foo->new(bar => 1);

# Method call
say $object->bar;
```