| 1 | use Renard::Incunabula::Common::Setup; | ||
| 2 | package Intertangle::Punchcard::Backend::Kiwisolver::Symbolic; | ||
| 3 | # ABSTRACT: Kiwisolver variable | ||
| 4 | $Intertangle::Punchcard::Backend::Kiwisolver::Symbolic::VERSION = '0.001'; | ||
| 5 | use Mu; | ||
| 6 | use Intertangle::API::Kiwisolver; | ||
| 7 | use Renard::Incunabula::Common::Types qw(InstanceOf); | ||
| 8 | use overload nomethod => \&_delegate_op; | ||
| 9 | |||
| 10 | has name => ( is => 'ro', predicate => 1 ); | ||
| 11 | |||
| 12 | has _delegate => ( | ||
| 13 | is => 'ro', | ||
| 14 | isa => ( | ||
| 15 | InstanceOf['Intertangle::API::Kiwisolver::Variable'] | ||
| 16 | | InstanceOf['Intertangle::API::Kiwisolver::Term'] | ||
| 17 | | InstanceOf['Intertangle::API::Kiwisolver::Expression'] | ||
| 18 | | InstanceOf['Intertangle::API::Kiwisolver::Constraint'] | ||
| 19 | ), | ||
| 20 | default => method() { | ||
| 21 | Intertangle::API::Kiwisolver::Variable->new; | ||
| 22 | }, | ||
| 23 | ); | ||
| 24 | |||
| 25 | method BUILD() { | ||
| 26 | if( $self->has_name ) { | ||
| 27 | $self->_delegate->setName( $self->name ); | ||
| 28 | } | ||
| 29 | } | ||
| 30 | |||
| 31 | method _delegate_op($other, $inv, $meth) { | ||
| 32 | my $op = overload::Method($self->_delegate, $meth); | ||
| 33 | die "Operator $meth not available" unless defined $op; | ||
| 34 | my $return = $op->($self->_delegate, defined $other && ref $other ? $other->_delegate : $other , $inv ); | ||
| 35 | |||
| 36 | if( $meth eq '""') { | ||
| 37 | return $return; | ||
| 38 | } | ||
| 39 | |||
| 40 | my $return_wrapper; | ||
| 41 | $return_wrapper = Intertangle::Punchcard::Backend::Kiwisolver::Symbolic->new( | ||
| 42 | _delegate => $return, | ||
| 43 | ); | ||
| 44 | |||
| 45 | $return_wrapper; | ||
| 46 | } | ||
| 47 | |||
| 48 | method value($value = undef) { | ||
| 49 | if( defined $value ) { | ||
| 50 | $self->_delegate->setValue( $value ); | ||
| 51 | } else { | ||
| 52 | $self->_delegate->value; | ||
| 53 | } | ||
| 54 | } | ||
| 55 | |||
| 56 | with qw(Intertangle::Punchcard::Data::Role::Variable); | ||
| 57 | |||
| 58 | 1; | ||
| 59 | |||
| 60 | __END__ | ||
| 61 | |||
| 62 | =pod | ||
| 63 | |||
| 64 | =encoding UTF-8 | ||
| 65 | |||
| 66 | =head1 NAME | ||
| 67 | |||
| 68 | Intertangle::Punchcard::Backend::Kiwisolver::Symbolic - Kiwisolver variable | ||
| 69 | |||
| 70 | =head1 VERSION | ||
| 71 | |||
| 72 | version 0.001 | ||
| 73 | |||
| 74 | =head1 EXTENDS | ||
| 75 | |||
| 76 | =over 4 | ||
| 77 | |||
| 78 | =item * L<Moo::Object> | ||
| 79 | |||
| 80 | =back | ||
| 81 | |||
| 82 | =head1 CONSUMES | ||
| 83 | |||
| 84 | =over 4 | ||
| 85 | |||
| 86 | =item * L<Intertangle::Punchcard::Data::Role::HasValue> | ||
| 87 | |||
| 88 | =item * L<Intertangle::Punchcard::Data::Role::Variable> | ||
| 89 | |||
| 90 | =back | ||
| 91 | |||
| 92 | =head1 ATTRIBUTES | ||
| 93 | |||
| 94 | =head2 name | ||
| 95 | |||
| 96 | Name for variable. | ||
| 97 | |||
| 98 | =head1 METHODS | ||
| 99 | |||
| 100 | =head2 C<has_name> | ||
| 101 | |||
| 102 | Predicate for C<name>. | ||
| 103 | |||
| 104 | =head2 BUILD | ||
| 105 | |||
| 106 | =head2 value | ||
| 107 | |||
| 108 | Set or get value for variable. | ||
| 109 | |||
| 110 | =head1 AUTHOR | ||
| 111 | |||
| 112 | Zakariyya Mughal <zmughal@cpan.org> | ||
| 113 | |||
| 114 | =head1 COPYRIGHT AND LICENSE | ||
| 115 | |||
| 116 | This software is copyright (c) 2019 by Zakariyya Mughal. | ||
| 117 | |||
| 118 | This is free software; you can redistribute it and/or modify it under | ||
| 119 | the same terms as the Perl 5 programming language system itself. | ||
| 120 | |||
| 121 | =cut |