| 1 | package Horris::Message; | ||||||||||||
| 2 | # ABSTRACT: Internal Message Structure For Horris | ||||||||||||
| 3 | |||||||||||||
| 4 | |||||||||||||
| 5 | 5 | ▶ | use Moose; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | 5 | ▶ | use Moose::Util::TypeConstraints; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | 5 | ▶ | use namespace::clean -except => qw(meta); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | |||||||||||||
| 9 | 5 | class_type 'Horris::Message::Address'; | |||||||||||
| 10 | |||||||||||||
| 11 | coerce 'Horris::Message::Address' | ||||||||||||
| 12 | => from 'Str' | ||||||||||||
| 13 | 0 | ▶ | => via { Horris::Message::Address->new($_) } | ||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||
| 14 | 5 | ; | |||||||||||
| 15 | |||||||||||||
| 16 | 5 | has from => ( | |||||||||||
| 17 | is => 'ro', | ||||||||||||
| 18 | isa => 'Horris::Message::Address', | ||||||||||||
| 19 | coerce => 1, | ||||||||||||
| 20 | required => 1, | ||||||||||||
| 21 | handles => [ qw(modifier nickname username hostname) ] | ||||||||||||
| 22 | ); | ||||||||||||
| 23 | |||||||||||||
| 24 | 5 | has channel => ( | |||||||||||
| 25 | is => 'ro', | ||||||||||||
| 26 | isa => 'Str', | ||||||||||||
| 27 | ); | ||||||||||||
| 28 | |||||||||||||
| 29 | 5 | has message => ( | |||||||||||
| 30 | is => 'ro', | ||||||||||||
| 31 | isa => 'Str', | ||||||||||||
| 32 | ); | ||||||||||||
| 33 | |||||||||||||
| 34 | has timestamp => ( | ||||||||||||
| 35 | is => 'ro', | ||||||||||||
| 36 | isa => 'Int', | ||||||||||||
| 37 | 0 | ▶ | default => sub { time() } | ||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||
| 38 | 5 | ); | |||||||||||
| 39 | |||||||||||||
| 40 | 5 | __PACKAGE__->meta->make_immutable; | |||||||||||
| 41 | |||||||||||||
| 42 | package Horris::Message::Address; | ||||||||||||
| 43 | 5 | ▶ | use Moose; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 44 | |||||||||||||
| 45 | has str_ref => ( | ||||||||||||
| 46 | is => 'ro', | ||||||||||||
| 47 | isa => 'ScalarRef', | ||||||||||||
| 48 | required => 1, | ||||||||||||
| 49 | 0 | ▶ | trigger => sub { | ||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||
| 50 | 0 | my $self = shift; | |||||||||||
| 51 | 0 | $self->__parsed(0); | |||||||||||
| 52 | }, | ||||||||||||
| 53 | 5 | ); | |||||||||||
| 54 | |||||||||||||
| 55 | 5 | has __parsed => ( | |||||||||||
| 56 | is => 'rw', | ||||||||||||
| 57 | isa => 'Bool', | ||||||||||||
| 58 | required => 1, | ||||||||||||
| 59 | default => 0, | ||||||||||||
| 60 | ); | ||||||||||||
| 61 | |||||||||||||
| 62 | 5 | has modifier => ( | |||||||||||
| 63 | is => 'ro', | ||||||||||||
| 64 | isa => 'Maybe[Str]', | ||||||||||||
| 65 | writer => 'set_modifier', | ||||||||||||
| 66 | ); | ||||||||||||
| 67 | |||||||||||||
| 68 | 5 | has nickname => ( | |||||||||||
| 69 | is => 'ro', | ||||||||||||
| 70 | isa => 'Maybe[Str]', | ||||||||||||
| 71 | writer => 'set_nickname', | ||||||||||||
| 72 | ); | ||||||||||||
| 73 | |||||||||||||
| 74 | 5 | has username => ( | |||||||||||
| 75 | is => 'ro', | ||||||||||||
| 76 | isa => 'Maybe[Str]', | ||||||||||||
| 77 | writer => 'set_username', | ||||||||||||
| 78 | ); | ||||||||||||
| 79 | |||||||||||||
| 80 | 5 | has hostname => ( | |||||||||||
| 81 | is => 'ro', | ||||||||||||
| 82 | isa => 'Maybe[Str]', | ||||||||||||
| 83 | writer => 'set_hostname', | ||||||||||||
| 84 | ); | ||||||||||||
| 85 | |||||||||||||
| 86 | 0 | ▶ | around BUILDARGS => sub { | ||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||
| 87 | 0 | my ($next, $class, @args) = @_; | |||||||||||
| 88 | |||||||||||||
| 89 | 0 | ▶ | if (@args == 1) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 90 | 0 | @args = (str_ref => \$args[0]); | |||||||||||
| 91 | } | ||||||||||||
| 92 | 0 | $next->($class, @args); | |||||||||||
| 93 | 5 | }; | |||||||||||
| 94 | |||||||||||||
| 95 | 5 | around qw(modifier nickname username hostname) => \&__check_parsed; | |||||||||||
| 96 | |||||||||||||
| 97 | 0 | ▶ | sub __check_parsed { | ||||||||||
|
Subroutine
:around: not called CC=6 SCAR=37.4
| |||||||||||||
| 98 | 0 | my ($next, $self, @args) = @_; | |||||||||||
| 99 | |||||||||||||
| 100 | 0 | ▶ | if (@args) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 101 | 0 | return $next->($self, @args); | |||||||||||
| 102 | } | ||||||||||||
| 103 | |||||||||||||
| 104 | 0 | ▶ | if (! $self->__parsed) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 105 | 0 | my $ref = $self->str_ref; | |||||||||||
| 106 | |||||||||||||
| 107 | 0 | $$ref =~ /^([^!]+)!([^@]+)@(.*)$/; | |||||||||||
| 108 | 0 | $self->set_modifier( '' ); | |||||||||||
| 109 | 0 | ▶ | $self->set_nickname( $1 || '' ); | ||||||||||
|
Condition0%0/2
$1 || ''
MC/DC0%0/1
$1 || ''
$1
Truth table0%0/2
A
A= $1
| |||||||||||||
| 110 | 0 | ▶ | $self->set_username( $2 || '' ); | ||||||||||
|
Condition0%0/2
$2 || ''
MC/DC0%0/1
$2 || ''
$2
Truth table0%0/2
A
A= $2
| |||||||||||||
| 111 | 0 | ▶ | $self->set_hostname( $3 || '' ); | ||||||||||
|
Condition0%0/2
$3 || ''
MC/DC0%0/1
$3 || ''
$3
Truth table0%0/2
A
A= $3
| |||||||||||||
| 112 | 0 | $self->__parsed(1); | |||||||||||
| 113 | } | ||||||||||||
| 114 | 0 | return $next->($self); | |||||||||||
| 115 | } | ||||||||||||
| 116 | |||||||||||||
| 117 | 5 | __PACKAGE__->meta->make_immutable(); | |||||||||||
| 118 | |||||||||||||
| 119 | 5 | 1; | |||||||||||
| 120 | |||||||||||||
| 121 | __END__ | ||||||||||||