| 1 | package Text::Xslate::Symbol; | ||||||||||
| 2 | 357 | ▶ | use Mouse; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | |||||||||||
| 4 | 357 | ▶ | use Text::Xslate::Util qw(p $DEBUG); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | use overload | ||||||||||
| 7 | 357 | ▶ | bool => sub() { 1 }, | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 790 | ▶ | '""' => sub { $_[0]->id }, | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 357 | fallback => 1, | |||||||||
| 10 | 357 | ; | |||||||||
| 11 | |||||||||||
| 12 | 357 | our @CARP_NOT = qw(Text::Xslate::Parser); | |||||||||
| 13 | |||||||||||
| 14 | 357 | ▶ | use constant _DUMP_DENOTE => scalar($DEBUG =~ /\b dump=denote \b/xmsi); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | |||||||||||
| 16 | 357 | has id => ( | |||||||||
| 17 | is => 'rw', | ||||||||||
| 18 | isa => 'Str', | ||||||||||
| 19 | required => 1, | ||||||||||
| 20 | ); | ||||||||||
| 21 | |||||||||||
| 22 | 357 | has lbp => ( # left binding power | |||||||||
| 23 | is => 'rw', | ||||||||||
| 24 | isa => 'Int', | ||||||||||
| 25 | |||||||||||
| 26 | lazy => 1, | ||||||||||
| 27 | default => 0, | ||||||||||
| 28 | ); | ||||||||||
| 29 | |||||||||||
| 30 | 357 | has ubp => ( # unary binding power | |||||||||
| 31 | is => 'rw', | ||||||||||
| 32 | isa => 'Int', | ||||||||||
| 33 | |||||||||||
| 34 | required => 0, | ||||||||||
| 35 | ); | ||||||||||
| 36 | |||||||||||
| 37 | has value => ( | ||||||||||
| 38 | is => 'rw', | ||||||||||
| 39 | |||||||||||
| 40 | lazy => 1, | ||||||||||
| 41 | builder => 'id', | ||||||||||
| 42 | 43794 | ▶ | trigger => sub { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 43 | 43794 | my($self) = @_; | |||||||||
| 44 | 43794 | $self->is_value(1); | |||||||||
| 45 | 43794 | return; | |||||||||
| 46 | }, | ||||||||||
| 47 | # default => sub{ | ||||||||||
| 48 | # if(!defined $_[0]) { #XXX: Mouse::XS's bug | ||||||||||
| 49 | # my(undef, $file, $line) = caller; | ||||||||||
| 50 | # warn "[bug] no invocant at $file line $line.\n"; | ||||||||||
| 51 | # return '(null)'; | ||||||||||
| 52 | # } | ||||||||||
| 53 | # return $_[0]->id | ||||||||||
| 54 | # }, | ||||||||||
| 55 | 357 | ); | |||||||||
| 56 | |||||||||||
| 57 | # some tokens have the counterpart token (e.g. '{' to '}') | ||||||||||
| 58 | 357 | has counterpart => ( | |||||||||
| 59 | is => 'rw', | ||||||||||
| 60 | isa => 'Str', | ||||||||||
| 61 | |||||||||||
| 62 | required => 0, | ||||||||||
| 63 | ); | ||||||||||
| 64 | |||||||||||
| 65 | # flags | ||||||||||
| 66 | 357 | has [ | |||||||||
| 67 | 'is_reserved', # set by reserve() | ||||||||||
| 68 | 'is_defined', # set by define() | ||||||||||
| 69 | 'is_block_end', # block ending markers | ||||||||||
| 70 | 'is_logical', # logical operators | ||||||||||
| 71 | 'is_comma', # comma like operators | ||||||||||
| 72 | 'is_value', # symbols with values | ||||||||||
| 73 | 'is_statement', # expr but a statement (e.g. assignment) | ||||||||||
| 74 | 'can_be_modifier', # statement modifiers (e.g. expr if cond) | ||||||||||
| 75 | ] => ( | ||||||||||
| 76 | is => 'rw', | ||||||||||
| 77 | isa => 'Bool', | ||||||||||
| 78 | required => 0, | ||||||||||
| 79 | ); | ||||||||||
| 80 | |||||||||||
| 81 | has nud => ( # null denotation | ||||||||||
| 82 | is => 'bare', | ||||||||||
| 83 | isa => 'CodeRef', | ||||||||||
| 84 | |||||||||||
| 85 | writer => 'set_nud', | ||||||||||
| 86 | reader => 'get_nud', | ||||||||||
| 87 | predicate => 'has_nud', | ||||||||||
| 88 | clearer => 'remove_nud', | ||||||||||
| 89 | |||||||||||
| 90 | 27449 | ▶ | trigger => sub{ | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 91 | 27449 | my($self) = @_; | |||||||||
| 92 | 27449 | $self->is_value(1); | |||||||||
| 93 | 27449 | return; | |||||||||
| 94 | }, | ||||||||||
| 95 | |||||||||||
| 96 | 357 | lazy_build => 1, | |||||||||
| 97 | |||||||||||
| 98 | required => 0, | ||||||||||
| 99 | ); | ||||||||||
| 100 | |||||||||||
| 101 | 357 | has led => ( # left denotation | |||||||||
| 102 | is => 'bare', | ||||||||||
| 103 | isa => 'CodeRef', | ||||||||||
| 104 | |||||||||||
| 105 | writer => 'set_led', | ||||||||||
| 106 | reader => 'get_led', | ||||||||||
| 107 | predicate => 'has_led', | ||||||||||
| 108 | clearer => 'remove_led', | ||||||||||
| 109 | |||||||||||
| 110 | lazy_build => 1, | ||||||||||
| 111 | |||||||||||
| 112 | required => 0, | ||||||||||
| 113 | ); | ||||||||||
| 114 | |||||||||||
| 115 | 357 | has std => ( # statement denotation | |||||||||
| 116 | is => 'bare', | ||||||||||
| 117 | isa => 'CodeRef', | ||||||||||
| 118 | |||||||||||
| 119 | writer => 'set_std', | ||||||||||
| 120 | reader => 'get_std', | ||||||||||
| 121 | predicate => 'has_std', | ||||||||||
| 122 | clearer => 'remove_std', | ||||||||||
| 123 | |||||||||||
| 124 | lazy_build => 1, | ||||||||||
| 125 | |||||||||||
| 126 | required => 0, | ||||||||||
| 127 | ); | ||||||||||
| 128 | |||||||||||
| 129 | |||||||||||
| 130 | 357 | has [qw(first second third)] => ( | |||||||||
| 131 | is => 'rw', | ||||||||||
| 132 | |||||||||||
| 133 | required => 0, | ||||||||||
| 134 | ); | ||||||||||
| 135 | |||||||||||
| 136 | 357 | has type => ( | |||||||||
| 137 | is => 'rw', | ||||||||||
| 138 | isa => 'Str', | ||||||||||
| 139 | |||||||||||
| 140 | required => 0, | ||||||||||
| 141 | ); | ||||||||||
| 142 | |||||||||||
| 143 | 357 | has arity => ( | |||||||||
| 144 | is => 'rw', | ||||||||||
| 145 | isa => 'Str', | ||||||||||
| 146 | |||||||||||
| 147 | lazy => 1, | ||||||||||
| 148 | default => 'name', | ||||||||||
| 149 | |||||||||||
| 150 | required => 0, | ||||||||||
| 151 | ); | ||||||||||
| 152 | |||||||||||
| 153 | 357 | has assignment => ( | |||||||||
| 154 | is => 'rw', | ||||||||||
| 155 | isa => 'Bool', | ||||||||||
| 156 | |||||||||||
| 157 | required => 0, | ||||||||||
| 158 | ); | ||||||||||
| 159 | |||||||||||
| 160 | #has scope => ( | ||||||||||
| 161 | # is => 'rw', | ||||||||||
| 162 | # isa => 'HashRef', | ||||||||||
| 163 | # | ||||||||||
| 164 | # required => 0, | ||||||||||
| 165 | #); | ||||||||||
| 166 | |||||||||||
| 167 | 357 | has line => ( | |||||||||
| 168 | is => 'rw', | ||||||||||
| 169 | isa => 'Int', | ||||||||||
| 170 | |||||||||||
| 171 | lazy => 1, | ||||||||||
| 172 | default => 0, | ||||||||||
| 173 | ); | ||||||||||
| 174 | |||||||||||
| 175 | |||||||||||
| 176 | 942 | ▶ | sub _build_nud { | ||||||||
|
Subroutine
_build_nud: called CC=1 SCAR=0.0
| |||||||||||
| 177 | 942 | return \&_nud_default; | |||||||||
| 178 | } | ||||||||||
| 179 | |||||||||||
| 180 | 0 | ▶ | sub _build_led { | ||||||||
|
Subroutine
_build_led: not called CC=1 SCAR=6.9
| |||||||||||
| 181 | 0 | return \&_led_default; | |||||||||
| 182 | } | ||||||||||
| 183 | |||||||||||
| 184 | 0 | ▶ | sub _build_std { | ||||||||
|
Subroutine
_build_std: not called CC=1 SCAR=6.9
| |||||||||||
| 185 | 0 | return \&_std_default; | |||||||||
| 186 | } | ||||||||||
| 187 | |||||||||||
| 188 | 944 | ▶ | sub _nud_default { | ||||||||
|
Subroutine
_nud_default: called CC=1 SCAR=0.0
| |||||||||||
| 189 | 944 | my($parser, $symbol) = @_; | |||||||||
| 190 | 944 | return $parser->default_nud($symbol); | |||||||||
| 191 | } | ||||||||||
| 192 | |||||||||||
| 193 | 0 | ▶ | sub _led_default { | ||||||||
|
Subroutine
_led_default: not called CC=1 SCAR=6.9
| |||||||||||
| 194 | 0 | my($parser, $symbol) = @_; | |||||||||
| 195 | 0 | return $parser->default_led($symbol); | |||||||||
| 196 | } | ||||||||||
| 197 | |||||||||||
| 198 | 0 | ▶ | sub _std_default { | ||||||||
|
Subroutine
_std_default: not called CC=1 SCAR=6.9
| |||||||||||
| 199 | 0 | my($parser, $symbol) = @_; | |||||||||
| 200 | 0 | return $parser->default_std($symbol); | |||||||||
| 201 | } | ||||||||||
| 202 | |||||||||||
| 203 | 44361 | ▶ | sub nud { | ||||||||
|
Subroutine
nud: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 204 | 44361 | my($self, $parser, @args) = @_; | |||||||||
| 205 | 44361 | $self->_dump_denote('nud', $parser) if _DUMP_DENOTE; | |||||||||
| 206 | 44361 | return $self->get_nud()->($parser, $self, @args); | |||||||||
| 207 | } | ||||||||||
| 208 | |||||||||||
| 209 | 3970 | ▶ | sub led { | ||||||||
|
Subroutine
led: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 210 | 3970 | my($self, $parser, @args) = @_; | |||||||||
| 211 | 3970 | $self->_dump_denote('led', $parser) if _DUMP_DENOTE; | |||||||||
| 212 | 3970 | return $self->get_led()->($parser, $self, @args); | |||||||||
| 213 | } | ||||||||||
| 214 | |||||||||||
| 215 | 27598 | ▶ | sub std { | ||||||||
|
Subroutine
std: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 216 | 27598 | my($self, $parser, @args) = @_; | |||||||||
| 217 | 27598 | $self->_dump_denote('std', $parser) if _DUMP_DENOTE; | |||||||||
| 218 | 27598 | return $self->get_std()->($parser, $self, @args); | |||||||||
| 219 | } | ||||||||||
| 220 | |||||||||||
| 221 | 193342 | ▶ | sub clone { | ||||||||
|
Subroutine
clone: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 222 | 193342 | my $self = shift; | |||||||||
| 223 | 193342 | return $self->meta->clone_object($self, @_); | |||||||||
| 224 | } | ||||||||||
| 225 | |||||||||||
| 226 | 0 | ▶ | sub _dump_denote { | ||||||||
|
Subroutine
_dump_denote: not called CC=2 SCAR=17.9
| |||||||||||
| 227 | 0 | my($self, $type, $parser) = @_; | |||||||||
| 228 | 0 | my $attr = $self->meta->get_attribute($type); | |||||||||
| 229 | |||||||||||
| 230 | 0 | ▶ | my $entity = $attr->has_value($self) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 231 | ? $attr->get_value($self) | ||||||||||
| 232 | : $parser->can('default_' . $type); | ||||||||||
| 233 | |||||||||||
| 234 | 0 | require B; | |||||||||
| 235 | 0 | my $cvgv = B::svref_2object($entity)->GV; | |||||||||
| 236 | 0 | printf STDERR "%s: %s::%s (%s:%s)\n", | |||||||||
| 237 | $type, | ||||||||||
| 238 | $cvgv->STASH->NAME, $cvgv->NAME, | ||||||||||
| 239 | $self->id, $self->line, | ||||||||||
| 240 | ; | ||||||||||
| 241 | } | ||||||||||
| 242 | |||||||||||
| 243 | 357 | ▶ | no Mouse; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 244 | 357 | __PACKAGE__->meta->make_immutable; | |||||||||
| 245 | |||||||||||
| 246 | __END__ | ||||||||||