File Coverage

blib/lib/RPerl/Operation/Expression/Operator/NamedUnary.pm
Criterion Covered Total %
statement 48 60 80.0
branch 7 12 58.3
condition 3 6 50.0
subroutine 7 8 87.5
pod n/a
total 65 86 75.5


line stmt bran cond sub pod time code
1             # [[[ HEADER ]]]
2             package RPerl::Operation::Expression::Operator::NamedUnary;
3 4     4   23 use strict;
  4         11  
  4         106  
4 4     4   22 use warnings;
  4         10  
  4         90  
5 4     4   18 use RPerl::AfterSubclass;
  4         8  
  4         803  
6             our $VERSION = 0.002_500;
7              
8             # [[[ OO INHERITANCE ]]]
9 4     4   29 use parent qw(RPerl::Operation::Expression::Operator);
  4         9  
  4         25  
10 4     4   276 use RPerl::Operation::Expression::Operator;
  4         9  
  4         2221  
11              
12             # [[[ CRITICS ]]]
13             ## no critic qw(ProhibitUselessNoCritic ProhibitMagicNumbers RequireCheckedSyscalls) # USER DEFAULT 1: allow numeric values & print operator
14             ## no critic qw(RequireInterpolationOfMetachars) # USER DEFAULT 2: allow single-quoted control characters & sigils
15              
16             # [[[ OO PROPERTIES ]]]
17             our hashref $properties = {};
18              
19             # [[[ OO PROPERTIES, CLASS PROPERTY AKA PACKAGE VARIABLE ]]]
20             # DEV NOTE, CORRELATION #rp020: upon adding new named op file lib/RPerl/Operation/Expression/Operator/Named*/* also add in Named*.pm and rperloperations.*
21             our string_hashref $NAMES = {
22             'chdir' => 'RPerl::Operation::Expression::Operator::NamedUnary::ChangeDirectory',
23             'cos' => 'RPerl::Operation::Expression::Operator::NamedUnary::Cosine',
24             'defined' => 'RPerl::Operation::Expression::Operator::NamedUnary::Defined',
25             'exists' => 'RPerl::Operation::Expression::Operator::NamedUnary::Exists',
26             '-e' => 'RPerl::Operation::Expression::Operator::NamedUnary::FileExists',
27             '-r' => 'RPerl::Operation::Expression::Operator::NamedUnary::FileReadable',
28             '-f' => 'RPerl::Operation::Expression::Operator::NamedUnary::FileRegular',
29             '-T' => 'RPerl::Operation::Expression::Operator::NamedUnary::FileText',
30             'length' => 'RPerl::Operation::Expression::Operator::NamedUnary::Length',
31             'log' => 'RPerl::Operation::Expression::Operator::NamedUnary::Log',
32             'rand' => 'RPerl::Operation::Expression::Operator::NamedUnary::Random',
33             'scalar' => 'RPerl::Operation::Expression::Operator::NamedUnary::Scalar',
34             'sin' => 'RPerl::Operation::Expression::Operator::NamedUnary::Sine',
35             'sqrt' => 'RPerl::Operation::Expression::Operator::NamedUnary::SquareRoot'
36             };
37              
38             # [[[ SUBROUTINES & OO METHODS ]]]
39              
40             sub ast_to_rperl__generate {
41 38     38   109 { my string_hashref::method $RETURN_TYPE };
  38         151  
42 38         147 ( my object $self, my string_hashref $modes) = @ARG;
43 38         255 my string_hashref $rperl_source_group = { PMC => q{} };
44 38         103 my string_hashref $rperl_source_subgroup;
45              
46             # RPerl::diag( 'in Operator::NamedUnary->ast_to_rperl__generate(), received $self = ' . "\n" . RPerl::Parser::rperl_ast__dump($self) . "\n" );
47              
48 38         112 my string $self_class = ref $self;
49              
50             # RPerl::diag( 'in Operator::NamedUnary->ast_to_rperl__generate(), have $self_class = ' . $self_class . "\n");
51              
52 38         91 my string $operator_name;
53 38 100 66     319 if ( $self_class eq 'Operation_91' ) { # Statement -> OP01_NAMED_UNARY_SCOLON
    50          
54 1         27 $operator_name = substr $self->{children}->[0], 0, -1;
55             }
56             elsif (( $self_class eq 'Operator_110' ) or # Operator -> OP10_NAMED_UNARY SubExpression
57             ( $self_class eq 'Operator_111' )
58             )
59             { # Operator -> OP10_NAMED_UNARY
60             # strip trailing whitespace, caused by the need to have the grammar match some tokens with a trailing whitespace, as with 'scalar ', etc.
61 37         379 $self->{children}->[0] =~ s/^([^\s]+)\s+$/$1/gxms;
62 37         172 $operator_name = $self->{children}->[0];
63             # RPerl::diag( 'in Operator::NamedUnary->ast_to_rperl__generate(), have $self->{children}->[0] = ' . q{'} . $self->{children}->[0] . q{'} . "\n" );
64             }
65             else {
66 0         0 die RPerl::Parser::rperl_rule__replace( 'ERROR ECOGEASRP00, CODE GENERATOR, ABSTRACT SYNTAX TO RPERL: Grammar rule '
67             . $self_class
68             . ' found where Operation_91, Operator_110, or Operator_111 expected, dying' )
69             . "\n";
70             }
71              
72             # RPerl::diag( 'in Operator::NamedUnary->ast_to_rperl__generate(), have $operator_name = ' . q{'} . $operator_name . q{'} . "\n" );
73              
74 38 50       258 if ( not exists $NAMES->{$operator_name} ) {
75             die q{ERROR ECOGEASRP19, CODE GENERATOR, ABSTRACT SYNTAX TO RPERL: unsupported or unrecognized named operator '}
76             . $operator_name
77             . q{' found where }
78 0         0 . ( join ', ', ( sort keys %{$NAMES} ) )
  0         0  
79             . ' expected, dying' . "\n";
80             }
81 38         146 my string $operator_class = $NAMES->{$operator_name};
82 38         684 my object $operator_object = $operator_class->new();
83              
84 38         1182 $rperl_source_subgroup = $operator_object->ast_to_rperl__generate( $self, $modes );
85 38         874 RPerl::Generator::source_group_append( $rperl_source_group, $rperl_source_subgroup );
86 38         883 return $rperl_source_group;
87             }
88              
89             sub ast_to_cpp__generate__CPPOPS_PERLTYPES {
90 0     0   0 { my string_hashref::method $RETURN_TYPE };
  0         0  
91 0         0 ( my object $self, my string_hashref $modes) = @ARG;
92 0         0 my string_hashref $cpp_source_group = { CPP => q{// <<< RP::O::E::O::NU __DUMMY_SOURCE_CODE CPPOPS_PERLTYPES >>>} . "\n" };
93              
94             #...
95 0         0 return $cpp_source_group;
96             }
97              
98             sub ast_to_cpp__generate__CPPOPS_CPPTYPES {
99 11     11   23 { my string_hashref::method $RETURN_TYPE };
  11         29  
100 11         31 ( my object $self, my string_hashref $modes) = @ARG;
101 11         41 my string_hashref $cpp_source_group = { CPP => q{} };
102 11         25 my string_hashref $cpp_source_subgroup;
103              
104             # RPerl::diag( 'in Operator::NamedUnary->ast_to_cpp__generate__CPPOPS_CPPTYPES(), received $self = ' . "\n" . RPerl::Parser::rperl_ast__dump($self) . "\n" );
105              
106 11         28 my string $self_class = ref $self;
107 11         20 my string $operator_name;
108 11 50 33     59 if ( $self_class eq 'Operation_91' ) { # Statement -> OP01_NAMED_UNARY_SCOLON
    50          
109 0         0 $operator_name = substr $self->{children}->[0], 0, -1;
110             }
111             elsif (( $self_class eq 'Operator_110' ) or # Operator -> OP10_NAMED_UNARY SubExpression
112             ( $self_class eq 'Operator_111' )
113             )
114             { # Operator -> OP10_NAMED_UNARY
115             # strip trailing whitespace, caused by the need to have the grammar match some tokens with a trailing whitespace, as with 'scalar ', etc.
116 11         101 $self->{children}->[0] =~ s/^([^\s]+)\s+$/$1/gxms;
117 11         38 $operator_name = $self->{children}->[0];
118             }
119             else {
120 0         0 die RPerl::Parser::rperl_rule__replace( 'ERROR ECOGEASCP00, CODE GENERATOR, ABSTRACT SYNTAX TO C++: Grammar rule '
121             . $self_class
122             . ' found where Operation_91, Operator_110 or Operator_111 expected, dying' )
123             . "\n";
124             }
125              
126             # RPerl::diag( 'in Operator::NamedUnary->ast_to_cpp__generate__CPPOPS_CPPTYPES(), have $operator_name = ' . q{'} . $operator_name . q{'} . "\n" );
127              
128 11 50       37 if ( not exists $NAMES->{$operator_name} ) {
129             die q{ERROR ECOGEASRP19, CODE GENERATOR, ABSTRACT SYNTAX TO RPERL: unsupported or unrecognized named operator '}
130             . $operator_name
131             . q{' found where }
132 0         0 . ( join ', ', ( sort keys %{$NAMES} ) )
  0         0  
133             . ' expected, dying' . "\n";
134             }
135 11         34 my string $operator_class = $NAMES->{$operator_name};
136 11         214 my object $operator_object = $operator_class->new();
137              
138 11         284 $cpp_source_subgroup = $operator_object->ast_to_cpp__generate__CPPOPS_CPPTYPES( $self, $modes );
139 11         242 RPerl::Generator::source_group_append( $cpp_source_group, $cpp_source_subgroup );
140 11         182 return $cpp_source_group;
141             }
142              
143             1; # end of class