summaryrefslogtreecommitdiff
path: root/bless-demo
blob: 931ee0635e378a64a0bb26c96c3dcb595cb32bcc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env perl

# Class for the object
package Sanctum::Bless::Class;
use strict;
use warnings;
use utf8;
use 5.010;
our $VERSION = 0.1;
use Data::Printer;    ## no critic (ProhibitDebuggingModules)

sub spit {
    my ($self) = @_;
    p $self;
    return;
}
1;

# Demonstration of bless()
package Sanctum::Bless::Demo;    ## no critic (ProhibitMultiplePackages)
use strict;
use warnings;
use utf8;
use 5.010;
our $VERSION = 0.1;              ## no critic (ProhibitReusedNames)

# Create a new hash reference
my $hash = { ayy => 'lmao', };

# Bless the hash reference into the Sanctum::Bless::Class. It thereby becomes
# an *instance* of "Sanctum::Bless:Class", which means it gains the "spit"
# method defined for it.
bless $hash, 'Sanctum::Bless::Class';

# Run the spit() method that's now available on the hashref.
$hash->spit();