AtteanX/SPARQL/Token.pm

filter: Statementstmt 95.3% 62 / 65 Branchbran 50.0% 1 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 93.7% 15 / 16 Podpod 100% 5 / 5 totaltotal 94.3% 83 / 88 CC 2 SCAR 1.2
CC
2
Cov
94%
as_string
2.0
a
1.1
anon
1.1
CRAP 1.1
« Test/Attean/MutableTimeCacheableQuadStore.pm ↑ Summary AtteanX/Serializer/NQuads.pm »
1 51 ▶use v5.14;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 51 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 =head1 NAME
5  
6 AtteanX::SPARQL::Token - Token objects used for parsing and serializing SPARQL
7  
8 =head1 VERSION
9  
10 This document describes AtteanX::SPARQL::Token version 0.041
11  
12 =head1 SYNOPSIS
13  
14 use v5.14;
15 use Attean;
16  
17 =head1 DESCRIPTION
18  
19 The AtteanX::SPARQL::Token class represents tokens produced and used
20 during parsing and serializing of SPARQL.
21  
22 =head1 ATTRIBUTES
23  
24 =over 4
25  
26 =item C<< type >>
27  
28 An integer indicating the token type, defined in L<AtteanX::Parser::Turtle::Constants>
29  
30 =item C<< start_line >>
31  
32 The line number in the source text that this token begins on.
33  
34 =item C<< start_column >>
35  
36 The column number in the source text that this token begins on.
37  
38 =item C<< line >>
39  
40 The line number in the source text that this token ends on.
41  
42 =item C<< column >>
43  
44 The column number in the source text that this token ends on.
45  
46 =item C<< args >>
47  
48 An array of values associated with the token (e.g. the integer value of an INT token).
49  
50 =back
51  
52 =head1 METHODS
53  
54 =over 4
55  
56 =cut
57  
58 package AtteanX::SPARQL::Token 0.041;
59  
60 51 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
61 51 ▶use Types::Standard qw(ArrayRef Str);
Subroutine BEGIN: called CC=1 SCAR=0.0
62 51 ▶use List::Util qw(mesh);
Subroutine BEGIN: called CC=1 SCAR=0.0
63 51 ▶use Sub::Util qw(set_subname);
Subroutine BEGIN: called CC=1 SCAR=0.0
64 51 ▶use Types::Standard qw(Int);
Subroutine BEGIN: called CC=1 SCAR=0.0
65 51 ▶use AtteanX::SPARQL::Constants;
Subroutine BEGIN: called CC=1 SCAR=0.0
66 51 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
67  
68 51 has type => ( is => 'ro', required => 1 );
69 51 has start_line => ( is => 'ro', required => 1 );
70 51 has start_column => ( is => 'ro', isa => Int, required => 1 );
71 51 has line => ( is => 'ro', isa => Int, required => 1 );
72 51 has column => ( is => 'ro', isa => Int, required => 1 );
73 51 has args => ( is => 'ro', isa => ArrayRef[Str]);
74  
75 51 extends 'AtteanX::Parser::Turtle::Token';
76  
77 =item C<< value >>
78  
79 Returns the token value.
80  
81 =cut
82  
83 1786 ▶sub value {
Subroutine value: called CC=1 SCAR=0.0
Pod documented
84 1786 my $self = shift;
85 1786 my $args = $self->args;
86 1786 return $args->[0];
87 }
88  
89 =item C<< fast_constructor ( $type, $start_line, $start_col, $line, $col, \@args ) >>
90  
91 Returns a new token object.
92  
93 =cut
94  
95 51 my @KEYS = qw(type start_line start_column line column args);
96 2797 ▶sub fast_constructor {
Subroutine fast_constructor: called CC=1 SCAR=0.0
Pod documented
97 2797 my $class = shift;
98 2797 return $class->new(
99 mesh \@KEYS, \@_
100 );
101 }
102  
103 {
104 51 my %tokens = (
105 a => [A, 'a'],
106 prefix => [PREFIX, '@prefix'],
107 base => [BASE, '@base'],
108 lparen => [LPAREN, '('],
109 rparen => [RPAREN, ')'],
110 lbracket => [LBRACKET, '['],
111 rbracket => [RBRACKET, ']'],
112 dot => [DOT, '.'],
113 comma => [COMMA, ','],
114 semicolon => [SEMICOLON, ';'],
115 hathat => [HATHAT, '^^'],
116  
117 lbrace => [LBRACE, '{'],
118 rbrace => [RBRACE, '}'],
119 op_andand => [ANDAND, '&&'],
120 anon => [ANON, '[]'],
121 op_bang => [BANG, '!'],
122 op_ge => [GE, '>='],
123 op_gt => [GT, '>'],
124 path_hat => [HAT, '^'],
125 op_le => [LE, '<='],
126 op_lt => [LT, '<'],
127 minus => [MINUS, '-'],
128 nil => [NIL, '()'],
129 op_ne => [NOTEQUALS, '!='],
130 path_or => [OR, '|'],
131 op_oror => [OROR, '||'],
132 op_plus => [PLUS, '+'],
133 question => [QUESTION, '?'],
134 slash => [SLASH, '/'],
135 star => [STAR, '*'],
136  
137 ltlt => [LTLT, '<<'],
138 gtgt => [GTGT, '>>'],
139 lannot => [LANNOT, '{|'],
140 rannot => [RANNOT, '|}'],
141 tilde => [TILDE, '~'],
142 );
143 51 for my $name (keys %tokens) {
144 1785 my ($type, $value) = @{ $tokens{ $name } };
145 0 ▶ my $code = sub {
Subroutine rbracket: not called CC=1 SCAR=1.2
Subroutine comma: called CC=1 SCAR=1.2
146 0 my $class = shift;
147 0 return $class->fast_constructor($type, -1, -1, -1, -1, [$value]);
148 1785 };
149 1785 Sub::Install::install_sub({
150 code => set_subname($name, $code),
151 as => $name
152 });
153 }
154 }
155  
156 =item C<< keyword( $kw ) >>
157  
158 Returns a new L<AtteanX::SPARQL::Token> object with the C<KEYWORD> type and
159 C<$kw> value.
160  
161 =cut
162  
163 224 ▶sub keyword {
Subroutine keyword: called CC=1 SCAR=0.0
Pod documented
164 224 my $class = shift;
165 224 my $kw = shift;
166 224 return $class->fast_constructor(KEYWORD, -1, -1, -1, -1, [uc($kw)]);
167 }
168  
169 =item C<< integer( $value ) >>
170  
171 Returns a new L<AtteanX::SPARQL::Token> object with the C<INTEGER> type and
172 the given C<$value>.
173  
174 =cut
175  
176 10 ▶sub integer {
Subroutine integer: called CC=1 SCAR=0.0
Pod documented
177 10 my $class = shift;
178 10 my $value = shift;
179 10 return $class->fast_constructor(INTEGER, -1, -1, -1, -1, [+$value] );
180 }
181  
182 =item C<< as_string >>
183  
184 Returns a string description of the token including the token type and any
185 associated values.
186  
187 =cut
188  
189 1 ▶sub as_string {
Subroutine as_string: called CC=2 SCAR=7.1
Pod documented
190 1 my $self = shift;
191 1 my $type = decrypt_constant($self->type);
192 1 my @args = @{ $self->args };
193 1 ▶ if (scalar(@args)) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @args) { } 1 0 1
194 1 return "$type(" . join(', ', @args) . ")";
195 } else {
196 0 return $type;
197 }
198 }
199  
200 51 __PACKAGE__->meta->make_immutable;
201  
202 51 1;
203  
204 =back
205  
206 =head1 BUGS
207  
208 Please report any bugs or feature requests to through the GitHub web interface
209 at L<https://github.com/kasei/attean/issues>.
210  
211 =head1 SEE ALSO
212  
213  
214  
215 =head1 AUTHOR
216  
217 Gregory Todd Williams C<< <gwilliams@cpan.org> >>
218  
219 =head1 COPYRIGHT
220  
221 Copyright (c) 2014--2026 Gregory Todd Williams.
222 This program is free software; you can redistribute it and/or modify it under
223 the same terms as Perl itself.
224  
225 =cut
« Test/Attean/MutableTimeCacheableQuadStore.pm ↑ Summary AtteanX/Serializer/NQuads.pm »