Advertisement
Guest User

Untitled

a guest
Dec 28th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 0.58 KB | None | 0 0
  1. # file Errors.pm
  2.  
  3. package Errors;
  4. use Moo;
  5.  
  6. # attribute errors
  7. has 'errors' => (
  8.     is => 'ro',
  9.     default => sub {
  10.         []
  11.     }
  12. );
  13.  
  14. # method get total errors
  15. sub totalErrors {
  16.     my $self = shift;
  17.    
  18.     return scalar(@{$self->errors});
  19. }
  20.  
  21. 1;
  22.  
  23. # file Person.pm
  24.  
  25. package Person;
  26. use Moo;
  27. extends qw/Errors/;
  28.  
  29. sub getTotalErrors {
  30.     my $self = shift;
  31.    
  32.     return $self->totalErrors;
  33. }
  34.  
  35. 1;
  36.  
  37. # file run.pl
  38.  
  39. #!/usr/bin/perl
  40.  
  41. use strict;
  42. use warnings;
  43. use lib './';
  44. use Person;
  45.  
  46. my $person = Person->new;
  47. print $person->getTotalErrors;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement