| 1 | package QML::File; | ||||||||||||||||||||||||||||
| 2 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use IO::File; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use base qw(Class::Accessor); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 2 | our $VERSION = 0.02; | |||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 2 | QML::File->mk_ro_accessors(qw(name objectType id)); | |||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 1 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 12 | 1 | my ( $class, $file ) = @_; | |||||||||||||||||||||||||||
| 13 | 1 | my $fileHandle = IO::File->new( $file, "r" ); | |||||||||||||||||||||||||||
| 14 | 1 | my ($name) = $file =~ /([^\.\\\/]+)\.qml$/; | |||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 1 | my $self = bless { | |||||||||||||||||||||||||||
| 17 | fileHandle => $fileHandle, | ||||||||||||||||||||||||||||
| 18 | name => $name, | ||||||||||||||||||||||||||||
| 19 | imports => [], | ||||||||||||||||||||||||||||
| 20 | objectType => '', | ||||||||||||||||||||||||||||
| 21 | id => {}, | ||||||||||||||||||||||||||||
| 22 | propertyDeclarations => [], | ||||||||||||||||||||||||||||
| 23 | signalDeclarations => [], | ||||||||||||||||||||||||||||
| 24 | javaScriptFunctions => [], | ||||||||||||||||||||||||||||
| 25 | objectProperties => [], | ||||||||||||||||||||||||||||
| 26 | childObjects => [] | ||||||||||||||||||||||||||||
| 27 | }, $class; | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 1 | $self->_parse; | |||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 1 | return $self; | |||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 1 | ▶ | sub _parse { | ||||||||||||||||||||||||||
|
Subroutine
_parse: called CC=21 SCAR=30.6
| |||||||||||||||||||||||||||||
| 35 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 1 | my $isInComment; | |||||||||||||||||||||||||||
| 38 | my $isInFunction; | ||||||||||||||||||||||||||||
| 39 | 1 | my $isInChildObject; | |||||||||||||||||||||||||||
| 40 | 1 | my $braceLevel = 0; | |||||||||||||||||||||||||||
| 41 | 1 | my $lineNum = 0; | |||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 1 | ▶ | if ( !$self->{fileHandle} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 44 | 0 | print "ERROR: Could not open $self->{name}\n"; | |||||||||||||||||||||||||||
| 45 | 0 | return; | |||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 1 | my @lines = $self->{fileHandle}->getlines; | |||||||||||||||||||||||||||
| 49 | 1 | foreach my $line (@lines) { | |||||||||||||||||||||||||||
| 50 | 38 | $lineNum++; | |||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | # Trim leading and trailing whitespace | ||||||||||||||||||||||||||||
| 53 | 38 | $line =~ s/^\s+//; | |||||||||||||||||||||||||||
| 54 | 38 | $line =~ s/\s+$//; | |||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | # Comment | ||||||||||||||||||||||||||||
| 57 | 38 | ▶ | next if ( $line =~ /^\/\// ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | # Long Comment | ||||||||||||||||||||||||||||
| 60 | 38 | ▶ | $isInComment = 1 if ( $line =~ /\/\*/ ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 61 | 38 | ▶ | if ($isInComment) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 62 | 4 | ▶ | $isInComment = 0 if ( $line =~ /\*\// ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 63 | 4 | next; | |||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | # FileSystemImport | ||||||||||||||||||||||||||||
| 67 | 34 | my ($filename) = $line =~ /import\s+"([^"]+)"/; | |||||||||||||||||||||||||||
| 68 | 34 | ▶ | if ( defined $filename ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 69 | 0 | push @{ $self->{imports} }, | |||||||||||||||||||||||||||
| 70 | { filename => $filename, line => $line, lineNum => $lineNum }; | ||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | # LibraryImport | ||||||||||||||||||||||||||||
| 74 | 34 | my ($importId) = $line =~ /import\s+([\w\d_\.]+)/; | |||||||||||||||||||||||||||
| 75 | 34 | ▶ | if ( defined $importId ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 76 | 2 | push @{ $self->{imports} }, | |||||||||||||||||||||||||||
| 77 | { name => $importId, line => $line, lineNum => $lineNum }; | ||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | # ObjectDeclaration | ||||||||||||||||||||||||||||
| 81 | 34 | ▶ | if ( !$self->{objectType} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 82 | 4 | my ($type) = $line =~ /^([\w\d_\.]+)/; | |||||||||||||||||||||||||||
| 83 | 4 | ▶ | if ( defined $type && $type ne 'import' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $type and $type ne "import"
MC/DC100%2/2
defined $type and $type ne "import"
defined $type
$type ne "import"
Truth table100%3/3
A and B
A= defined $typeB= $type ne "import"
| |||||||||||||||||||||||||||||
| 84 | $self->{objectType} = | ||||||||||||||||||||||||||||
| 85 | 1 | { name => $type, line => $line, lineNum => $lineNum }; | |||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 34 | ▶ | if ( $braceLevel == 1 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | # PropertyDeclaration | ||||||||||||||||||||||||||||
| 92 | 20 | my ( $propertyType, $identifier ) = | |||||||||||||||||||||||||||
| 93 | $line =~ /^property\s+([\w\d_]+)\s+([\w\d_]+)/; | ||||||||||||||||||||||||||||
| 94 | 20 | ▶ | if ( defined $propertyType ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 95 | 1 | push @{ $self->{propertyDeclarations} }, | |||||||||||||||||||||||||||
| 96 | { | ||||||||||||||||||||||||||||
| 97 | type => $propertyType, | ||||||||||||||||||||||||||||
| 98 | name => $identifier, | ||||||||||||||||||||||||||||
| 99 | line => $line, | ||||||||||||||||||||||||||||
| 100 | lineNum => $lineNum | ||||||||||||||||||||||||||||
| 101 | }; | ||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | # SignalDeclaration | ||||||||||||||||||||||||||||
| 105 | 20 | my ($signalName) = $line =~ /^signal\s+([\w\d_]+)/; | |||||||||||||||||||||||||||
| 106 | 20 | ▶ | if ( defined $signalName ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 107 | 1 | push @{ $self->{signalDeclarations} }, | |||||||||||||||||||||||||||
| 108 | { name => $signalName, line => $line, lineNum => $lineNum }; | ||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | # JavaScriptFunctions | ||||||||||||||||||||||||||||
| 112 | 20 | my ($functionName) = $line =~ /^function\s+([\w\d_]+)/; | |||||||||||||||||||||||||||
| 113 | 20 | ▶ | if ( defined $functionName ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 114 | 2 | push @{ $self->{javaScriptFunctions} }, | |||||||||||||||||||||||||||
| 115 | { name => $functionName, line => $line, lineNum => $lineNum }; | ||||||||||||||||||||||||||||
| 116 | 2 | $isInFunction = 1; | |||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | # ObjectProperties | ||||||||||||||||||||||||||||
| 120 | 20 | my ($propertyName) = $line =~ /^([\w\d_\.]+)\s*:/; | |||||||||||||||||||||||||||
| 121 | 20 | ▶ | if ( defined $propertyName ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 122 | 8 | push @{ $self->{objectProperties} }, | |||||||||||||||||||||||||||
| 123 | { name => $propertyName, line => $line, lineNum => $lineNum }; | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | # ID | ||||||||||||||||||||||||||||
| 126 | 8 | ▶ | if ( !defined $self->{id}->{name} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 127 | 1 | my ($id) = $line =~ /^id\s*:\s*([\w\d_\.]+)/; | |||||||||||||||||||||||||||
| 128 | 1 | ▶ | if ( defined $id ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 129 | $self->{id} = | ||||||||||||||||||||||||||||
| 130 | 1 | { name => $id, line => $line, lineNum => $lineNum }; | |||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | # Child objects | ||||||||||||||||||||||||||||
| 136 | 20 | my ($childType) = $line =~ /^([\w\d_\.]+)\s*\{/; | |||||||||||||||||||||||||||
| 137 | 20 | ▶ | if ( defined $childType ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 138 | 1 | ▶ | next if $childType =~ /^anchors|font$/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 139 | 1 | push @{ $self->{childObjects} }, | |||||||||||||||||||||||||||
| 140 | { type => $childType, line => $line, lineNum => $lineNum }; | ||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | # Curly braces | ||||||||||||||||||||||||||||
| 145 | 34 | $braceLevel += ( $line =~ tr/\{// ); | |||||||||||||||||||||||||||
| 146 | 34 | $braceLevel -= ( $line =~ tr/\}// ); | |||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | 1 | ▶ | sub imports { | ||||||||||||||||||||||||||
|
Subroutine
imports: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 151 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||
| 152 | 1 | return @{ $self->{imports} }; | |||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | 1 | ▶ | sub propertyDeclarations { | ||||||||||||||||||||||||||
|
Subroutine
propertyDeclarations: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 156 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||
| 157 | 1 | return @{ $self->{propertyDeclarations} }; | |||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | 1 | ▶ | sub signalDeclarations { | ||||||||||||||||||||||||||
|
Subroutine
signalDeclarations: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 161 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||
| 162 | 1 | return @{ $self->{signalDeclarations} }; | |||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | 1 | ▶ | sub javaScriptFunctions { | ||||||||||||||||||||||||||
|
Subroutine
javaScriptFunctions: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 166 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||
| 167 | 1 | return @{ $self->{javaScriptFunctions} }; | |||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | 1 | ▶ | sub objectProperties { | ||||||||||||||||||||||||||
|
Subroutine
objectProperties: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 171 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||
| 172 | 1 | return @{ $self->{objectProperties} }; | |||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | 1 | ▶ | sub childObjects { | ||||||||||||||||||||||||||
|
Subroutine
childObjects: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 176 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||
| 177 | 1 | return @{ $self->{childObjects} }; | |||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | 2 | 1; | |||||||||||||||||||||||||||
| 181 | __END__ | ||||||||||||||||||||||||||||