has request_type => ( is => 'ro', isa => 'Int', lazy => 1, default => undef, init_arg => undef, );
has '+request_type' => ( default => 32, ); # default
after create_request => sub {
my $self = shift;
return unless $self->cipher;
require Crypt::TripleDES;
my $ciphered_text = sprintf "Phone%s\n%s",
$self->trm_id,
unpack('H*', Crypt::TripleDES->new->encrypt3($self->request, $self->ciphering_key));
$self->request($ciphered_text)
};
method create_request() { #
my $req_node = inner() ;
$req_node->appendChild( $self->_create_extra_node($_, $self->$_) ) foreach qw(password serial);
$req_node->appendChild( $self->_create_simple_node('protocol-version', $self->protocol_version) );
$req_node->appendChild( $self->_create_simple_node('terminal-id', $self->trm_id) );
$req_node->appendChild( $self->_create_simple_node('request-type', $self->request_type) );
my $xml = XML::LibXML::Document->new('1.0', 'utf-8');
$xml->setDocumentElement($req_node);
$self->request($xml->toString)
}
augment create_request => sub { #
my $self = shift;
my $xml = $self->_create_simple_node('request');
$xml->appendChild( $self->_create_extra_node('phone', $self->phone) );
$xml
};
use MooseX::Declare;
class Business::Qiwi {
has trm_id => ( is => 'rw', isa => 'Str', required => 1, );
has password => ( is => 'rw', isa => 'Str', required => 1, );
has serial => ( is => 'rw', isa => 'Str', required => 1, );
#...
method get_balance() {
# ...
}
};
class Business::Qiwi::Balance extends Business::Qiwi::Request {
# ...
};
my $self = shift;
. Invocant is available in the method automatically (under the name $ self).__PACKAGE__->meta->make_immutable
use MooseX::Types -declare => [qw(Date EntriesList IdsList TxnsList BillsList)]; #
use MooseX::Types::Moose qw(Int Str ArrayRef HashRef); # Moose
subtype Date => as Str => where { /^\d{2}\.\d{2}\.\d{4}$/ } => message { 'Date must be provided in DD.MM.YYYY format' }; # Str
subtype IdsList => as ArrayRef[Int] ; # has
method create_bill( Num $amount, Str $to, Str $txn, Str $comment, Bool $sms_notify?, Bool $call_notify?, Int $confirm_time? ) { # //
# ...
}
method get_bill_status( BillsList $bill ) { # !
# ...
}
use strict;
use warnings;
use Test::More tests => 3;
{
package Paper; use Moose;
package Scissors; use Moose;
package Rock; use Moose;
package Lizard; use Moose;
package Spock; use Moose;
package Game;
use Moose;
use MooseX::MultiMethod;
multi method play (Paper $x, Rock $y) { 1 }
multi method play (Paper $x, Spock $y) { 1 }
multi method play (Scissors $x, Paper $y) { 1 }
multi method play (Scissors $x, Lizard $y) { 1 }
multi method play (Rock $x, Scissors $y) { 1 }
multi method play (Rock $x, Lizard $y) { 1 }
multi method play (Lizard $x, Paper $y) { 1 }
multi method play (Lizard $x, Spock $y) { 1 }
multi method play (Spock $x, Rock $y) { 1 }
multi method play (Spock $x, Scissors $y) { 1 }
multi method play (Any $x, Any $y) { 0 }
}
my $game = Game->new;
ok($game->play(Spock->new, Scissors->new), 'Spock smashes Scissors');
ok(!$game->play(Lizard->new, Rock->new), 'Rock crushes Lizard');
ok(!$game->play(Spock->new, Paper->new), 'Paper disproves Spock');
1;
Source: https://habr.com/ru/post/59542/