| 1 | package Panotools::Script::Line; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 15 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 15 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | |||||||||||||||||||||
| 6 | 15 | ▶ | use Storable qw/ dclone /; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | |||||||||||||||||||||
| 8 | =head1 NAME | ||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | Panotools::Script::Line - Panorama Tools script data | ||||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | =head1 SYNOPSIS | ||||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | Base class for a line in a panotools script | ||||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | =head1 DESCRIPTION | ||||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | A line starts with a single letter identifier then a series of | ||||||||||||||||||||
| 19 | namevalue items separated by whitespace | ||||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | =head1 USAGE | ||||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | my $line = new Panotools::Script::Line::Foo; | ||||||||||||||||||||
| 24 | |||||||||||||||||||||
| 25 | =cut | ||||||||||||||||||||
| 26 | |||||||||||||||||||||
| 27 | sub new | ||||||||||||||||||||
| 28 | 343 | ▶ | { | ||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.2
Pod
undocumented
| |||||||||||||||||||||
| 29 | 343 | my $class = shift; | |||||||||||||||||||
| 30 | 343 | ▶ | $class = ref $class || $class; | ||||||||||||||||||
|
Condition33%1/3
ref $class || $class
MC/DC0%0/2
ref $class || $class
ref $class
$class
Truth table33%1/3
A || B
A= ref $classB= $class
| |||||||||||||||||||||
| 31 | 343 | my $self = bless {}, $class; | |||||||||||||||||||
| 32 | 343 | $self->_defaults; | |||||||||||||||||||
| 33 | 343 | return $self; | |||||||||||||||||||
| 34 | } | ||||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | =pod | ||||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | my $identifier = $line->Identifier; | ||||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | =cut | ||||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | sub Identifier | ||||||||||||||||||||
| 43 | 0 | ▶ | { | ||||||||||||||||||
|
Subroutine
Identifier: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 44 | 0 | return '#'; | |||||||||||||||||||
| 45 | } | ||||||||||||||||||||
| 46 | |||||||||||||||||||||
| 47 | =pod | ||||||||||||||||||||
| 48 | |||||||||||||||||||||
| 49 | $line->Parse ('f a1.0 b2.0 bar3.0'); | ||||||||||||||||||||
| 50 | |||||||||||||||||||||
| 51 | =cut | ||||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | sub Parse | ||||||||||||||||||||
| 54 | 281 | ▶ | { | ||||||||||||||||||
|
Subroutine
Parse: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||
| 55 | 281 | my $self = shift; | |||||||||||||||||||
| 56 | 281 | ▶ | my $string = shift || return 0; | ||||||||||||||||||
|
Condition50%1/2
shift() || (return 0)
MC/DC0%0/1
shift() || (return 0)
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||
| 57 | 281 | my $valid = $self->_valid; | |||||||||||||||||||
| 58 | 281 | my @res = $string =~ / ([a-zA-Z][^ "]+)|([a-zA-Z][a-z]*"[^"]+")/g; | |||||||||||||||||||
| 59 | 281 | for my $token (grep { defined $_ } @res) | |||||||||||||||||||
| 60 | { | ||||||||||||||||||||
| 61 | 2363 | my ($key, $value) = $token =~ /$valid/; | |||||||||||||||||||
| 62 | 2363 | ▶ | next unless defined $key; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 63 | 2322 | $self->{$key} = $value; | |||||||||||||||||||
| 64 | } | ||||||||||||||||||||
| 65 | 281 | $self->_sanitise; | |||||||||||||||||||
| 66 | 281 | return 1; | |||||||||||||||||||
| 67 | } | ||||||||||||||||||||
| 68 | |||||||||||||||||||||
| 69 | =pod | ||||||||||||||||||||
| 70 | |||||||||||||||||||||
| 71 | my $string = $line->Assemble; | ||||||||||||||||||||
| 72 | |||||||||||||||||||||
| 73 | =cut | ||||||||||||||||||||
| 74 | |||||||||||||||||||||
| 75 | sub Assemble | ||||||||||||||||||||
| 76 | 113 | ▶ | { | ||||||||||||||||||
|
Subroutine
Assemble: called CC=3 SCAR=11.2
Pod
undocumented
| |||||||||||||||||||||
| 77 | 113 | my $self = shift; | |||||||||||||||||||
| 78 | 113 | $self->_sanitise; | |||||||||||||||||||
| 79 | 113 | my @tokens; | |||||||||||||||||||
| 80 | 113 | for my $entry (sort keys %{$self}) | |||||||||||||||||||
| 81 | { | ||||||||||||||||||||
| 82 | 764 | push @tokens, $entry . $self->{$entry}; | |||||||||||||||||||
| 83 | } | ||||||||||||||||||||
| 84 | 113 | ▶ | return (join ' ', ($self->Identifier, @tokens)) ."\n" if (@tokens); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 85 | 0 | return ''; | |||||||||||||||||||
| 86 | } | ||||||||||||||||||||
| 87 | |||||||||||||||||||||
| 88 | =pod | ||||||||||||||||||||
| 89 | |||||||||||||||||||||
| 90 | $line->Set (a => 'something', b => 2); | ||||||||||||||||||||
| 91 | |||||||||||||||||||||
| 92 | =cut | ||||||||||||||||||||
| 93 | |||||||||||||||||||||
| 94 | sub Set | ||||||||||||||||||||
| 95 | 9 | ▶ | { | ||||||||||||||||||
|
Subroutine
Set: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 96 | 9 | my $self = shift; | |||||||||||||||||||
| 97 | 9 | my %hash = @_; | |||||||||||||||||||
| 98 | 9 | for my $entry (sort keys %hash) | |||||||||||||||||||
| 99 | { | ||||||||||||||||||||
| 100 | 59 | $self->{$entry} = $hash{$entry}; | |||||||||||||||||||
| 101 | } | ||||||||||||||||||||
| 102 | 9 | $self->_sanitise; | |||||||||||||||||||
| 103 | } | ||||||||||||||||||||
| 104 | |||||||||||||||||||||
| 105 | =pod | ||||||||||||||||||||
| 106 | |||||||||||||||||||||
| 107 | Clone a line object | ||||||||||||||||||||
| 108 | |||||||||||||||||||||
| 109 | $clone = $l->Clone; | ||||||||||||||||||||
| 110 | |||||||||||||||||||||
| 111 | =cut | ||||||||||||||||||||
| 112 | |||||||||||||||||||||
| 113 | sub Clone | ||||||||||||||||||||
| 114 | 82 | ▶ | { | ||||||||||||||||||
|
Subroutine
Clone: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 115 | 82 | my $self = shift; | |||||||||||||||||||
| 116 | 82 | dclone ($self); | |||||||||||||||||||
| 117 | } | ||||||||||||||||||||
| 118 | |||||||||||||||||||||
| 119 | 19 | ▶ | sub _defaults {} | ||||||||||||||||||
|
Subroutine
_defaults: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 120 | |||||||||||||||||||||
| 121 | 0 | ▶ | sub _valid { return '^(.)(.*)' } | ||||||||||||||||||
|
Subroutine
_valid: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 122 | |||||||||||||||||||||
| 123 | sub _sanitise | ||||||||||||||||||||
| 124 | 416 | ▶ | { | ||||||||||||||||||
|
Subroutine
_sanitise: called CC=3 SCAR=11.0
| |||||||||||||||||||||
| 125 | 416 | my $self = shift; | |||||||||||||||||||
| 126 | 416 | my $valid = $self->_valid; | |||||||||||||||||||
| 127 | 416 | for my $key (keys %{$self}) | |||||||||||||||||||
| 128 | { | ||||||||||||||||||||
| 129 | 3873 | ▶ | delete $self->{$key} unless (grep /$valid/, $key); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 130 | } | ||||||||||||||||||||
| 131 | } | ||||||||||||||||||||
| 132 | |||||||||||||||||||||
| 133 | 15 | 1; | |||||||||||||||||||
| 134 | |||||||||||||||||||||