| 1 | package Const::Introspect::C::Constant; | ||||||||||
| 2 | |||||||||||
| 3 | 2 | ▶ | use 5.020; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 2 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 2 | ▶ | use experimental qw( signatures ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | # ABSTRACT: Class representing a C/C++ constant | ||||||||||
| 8 | 2 | our $VERSION = '0.01'; # VERSION | |||||||||
| 9 | |||||||||||
| 10 | |||||||||||
| 11 | 2 | has c => ( | |||||||||
| 12 | is => 'ro', | ||||||||||
| 13 | required => 1, | ||||||||||
| 14 | ); | ||||||||||
| 15 | |||||||||||
| 16 | |||||||||||
| 17 | 2 | has name => ( | |||||||||
| 18 | is => 'ro', | ||||||||||
| 19 | required => 1, | ||||||||||
| 20 | ); | ||||||||||
| 21 | |||||||||||
| 22 | |||||||||||
| 23 | 2 | has raw_value => ( | |||||||||
| 24 | is => 'ro', | ||||||||||
| 25 | ); | ||||||||||
| 26 | |||||||||||
| 27 | |||||||||||
| 28 | has value => ( | ||||||||||
| 29 | is => 'ro', | ||||||||||
| 30 | lazy => 1, | ||||||||||
| 31 | 9 | ▶ | default => sub ($self) { | ||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||
| 32 | 9 | my $type = $self->type; | |||||||||
| 33 | $type eq 'other' | ||||||||||
| 34 | ? undef | ||||||||||
| 35 | 9 | ▶ | : do { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 36 | 7 | local $@ = ''; | |||||||||
| 37 | 7 | my $value = eval { $self->c->compute_expression_value($type, $self->name) }; | |||||||||
| 38 | # TODO: diagnostic on `fail` | ||||||||||
| 39 | 7 | ▶ | $@ ? undef : $value; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 40 | }; | ||||||||||
| 41 | }, | ||||||||||
| 42 | 2 | ); | |||||||||
| 43 | |||||||||||
| 44 | |||||||||||
| 45 | has type => ( | ||||||||||
| 46 | is => 'ro', | ||||||||||
| 47 | 16 | ▶ | isa => sub { | ||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.6
| |||||||||||
| 48 | 16 | ▶ | die "type should be one of: string, int, long, pointer, float, double or other" | ||||||||
|
Branch: 1 branch
| |||||||||||
| 49 | unless $_[0] =~ /^(string|int|long|pointer|float|double|other)$/; | ||||||||||
| 50 | }, | ||||||||||
| 51 | lazy => 1, | ||||||||||
| 52 | 9 | ▶ | default => sub ($self) { | ||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||
| 53 | 9 | local $@ = ''; | |||||||||
| 54 | 9 | my $type = eval { $self->c->compute_expression_type($self->name) }; | |||||||||
| 55 | # TODO: diagnostic on `other` | ||||||||||
| 56 | 9 | ▶ | $@ ? 'other' : $type; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 57 | }, | ||||||||||
| 58 | 2 | ); | |||||||||
| 59 | |||||||||||
| 60 | 2 | ▶ | no Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 61 | |||||||||||
| 62 | 2 | 1; | |||||||||
| 63 | |||||||||||
| 64 | __END__ | ||||||||||