File: Delta.pm

package info (click to toggle)
libclass-tiny-perl 1.008-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 284 kB
  • sloc: perl: 442; makefile: 2
file content (30 lines) | stat: -rw-r--r-- 491 bytes parent folder | download | duplicates (4)
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
use 5.006;
use strict;
use warnings;

package Delta;

our $counter   = 0;
our $exception = 0;

use Carp ();

use Class::Tiny qw/foo bar/;

sub BUILD {
    my $self = shift;
    my $args = shift;
    Carp::croak("foo must be positive")
      unless defined $self->foo && $self->foo > 0;

    $self->bar(42) unless defined $self->bar;
    $counter++;
}

sub DEMOLISH {
    my $self = shift;
    $counter--   if $counter > 0;
    $exception++ if keys %$self > 2; # Echo will delete first
}

1;