| 1 | package PGPLOT::Device; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | # ABSTRACT: autogenerate PGPLOT device names | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 3 | our $VERSION = '0.12'; | |||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 3 | our %Default = ( device => 'xs', ); | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 3 | our $ephemeral = qr{^xw$}; | |||||||||||||||||||||||||||
| 14 | 3 | our $NDevices; | |||||||||||||||||||||||||||
| 15 | 3 | our %PGDevice; | |||||||||||||||||||||||||||
| 16 | 3 | our %DevMap; | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | sub _croak { | ||||||||||||||||||||||||||||
| 19 | 0 | ▶ | require Carp; | ||||||||||||||||||||||||||
|
Subroutine
_croak: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 20 | 0 | goto \&Carp::croak; | |||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | sub new { | ||||||||||||||||||||||||||||
| 95 | 1 | ▶ | my $class = shift; | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=3.1
Pod
documented
| |||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 1 | _class_init(); | |||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | 0 | my $self = { | |||||||||||||||||||||||||||
| 100 | devn => 1, | ||||||||||||||||||||||||||||
| 101 | last => undef, | ||||||||||||||||||||||||||||
| 102 | vars => {} }; | ||||||||||||||||||||||||||||
| 103 | 0 | bless $self, $class; | |||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 0 | $self->_initialize( @_ ); | |||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | # need to keep track of whether there was an initial prefix | ||||||||||||||||||||||||||||
| 108 | 0 | $self->{init_prefix} = defined $self->{prefix}; | |||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | 0 | $self; | |||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | sub _class_init { | ||||||||||||||||||||||||||||
| 114 | 1 | ▶ | return if $NDevices; | ||||||||||||||||||||||||||
|
Subroutine
_class_init: called CC=3 SCAR=20.0
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | 1 | require PGPLOT; | |||||||||||||||||||||||||||
| 117 | 0 | PGPLOT::pgqndt( $NDevices ); | |||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | 0 | my @devices; | |||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | 0 | for my $didx ( 1 .. $NDevices ) { | |||||||||||||||||||||||||||
| 122 | 0 | my ( $type, $tlen, $descr, $dlen, $inter ); | |||||||||||||||||||||||||||
| 123 | 0 | PGPLOT::pgqdt( $didx, $type, $tlen, $descr, $dlen, $inter ); | |||||||||||||||||||||||||||
| 124 | 0 | $type =~ s{/}{}; | |||||||||||||||||||||||||||
| 125 | 0 | $PGDevice{ lc $type } = { | |||||||||||||||||||||||||||
| 126 | idx => $didx, | ||||||||||||||||||||||||||||
| 127 | type => lc( $type ), | ||||||||||||||||||||||||||||
| 128 | tlen => $tlen, | ||||||||||||||||||||||||||||
| 129 | descr => $descr, | ||||||||||||||||||||||||||||
| 130 | dlen => $dlen, | ||||||||||||||||||||||||||||
| 131 | inter => $inter, | ||||||||||||||||||||||||||||
| 132 | }; | ||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | 0 | push @devices, lc $type; | |||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | 0 | require Text::Abbrev; | |||||||||||||||||||||||||||
| 138 | 0 | Text::Abbrev::abbrev( \%DevMap, @devices ); | |||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | sub _initialize { | ||||||||||||||||||||||||||||
| 143 | 0 | ▶ | my $opts = 'HASH' eq ref $_[-1] ? pop @_ : {}; | ||||||||||||||||||||||||||
|
Subroutine
_initialize: not called CC=10 SCAR=47.0
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | 0 | my ( $self, $spec ) = @_; | |||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | 0 | ▶ | my %spec = defined $spec ? $self->_parse_spec( $spec ) : (); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | # don't allow an override to change the device | ||||||||||||||||||||||||||||
| 150 | 0 | ▶ | delete $spec{device} if defined $self->{device}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | # don't allow an override to change an initial prefix | ||||||||||||||||||||||||||||
| 153 | 0 | ▶ | delete $spec{prefix} if $self->{init_prefix}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | # fill the object | ||||||||||||||||||||||||||||
| 156 | 0 | $self->{$_} = $spec{$_} for keys %spec; | |||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | 0 | ▶ | unless ( defined $self->{device} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 159 | 0 | $self->{device} = $Default{device}; | |||||||||||||||||||||||||||
| 160 | 0 | $self->{devinfo} = $PGDevice{ $DevMap{ $Default{device} } }; | |||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | 0 | ▶ | if ( exists $opts->{vars} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 164 | _croak( "vars attribute must be a hash\n" ) | ||||||||||||||||||||||||||||
| 165 | 0 | ▶ | unless 'HASH' eq ref $opts->{vars}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | 0 | $self->{vars} = $opts->{vars}; | |||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | 0 | ▶ | $self->{ask} = $self->is_interactive && $self->is_const; | ||||||||||||||||||||||||||
|
Condition0%0/3
$self->is_interactive && $self->is_const
MC/DC0%0/2
$self->is_interactive && $self->is_const
$self->is_interactive
$self->is_const
Truth table0%0/3
A && B
A= $self->is_interactiveB= $self->is_const
| |||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | 0 | $self; | |||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | sub override { | ||||||||||||||||||||||||||||
| 194 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
override: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||
| 196 | 0 | ▶ | if ( !$self->is_interactive() ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 197 | 0 | $self->_initialize( @_ ); | |||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||
| 200 | 0 | $self; | |||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||
| 213 | sub devn { | ||||||||||||||||||||||||||||
| 214 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
devn: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 215 | 0 | my $old = $self->{devn}; | |||||||||||||||||||||||||||
| 216 | 0 | ▶ | $self->{devn} = shift if @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||
| 218 | 0 | $old; | |||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||
| 232 | 0 | ▶ | sub ask { $_[0]->{ask} } | ||||||||||||||||||||||||||
|
Subroutine
ask: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||
| 235 | sub _parse_spec { | ||||||||||||||||||||||||||||
| 236 | 0 | ▶ | my ( $self, $spec ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_parse_spec: not called CC=15 SCAR=54.8
| |||||||||||||||||||||||||||||
| 237 | 0 | my ( $prefix, $device ); | |||||||||||||||||||||||||||
| 238 | 0 | my %spec; | |||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||
| 241 | # split into prefix and /device. set to prefix only, if no match, | ||||||||||||||||||||||||||||
| 242 | # as that'll be the case if no device was specified. | ||||||||||||||||||||||||||||
| 243 | 0 | ▶ | $prefix = $spec | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 244 | if 0 == ( ( $prefix, $device ) = $spec =~ m{(.*)/([^/]+)$} ); | ||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||
| 247 | # be careful that a multi-directory path (dir/prefix) doesn't get | ||||||||||||||||||||||||||||
| 248 | # translated into file/device. If /prefix looks like a real PGPLOT | ||||||||||||||||||||||||||||
| 249 | # device, this will fail horribly. | ||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||
| 251 | # if there's already a device, discard /device if it looks like | ||||||||||||||||||||||||||||
| 252 | # a PGPLOT device, else append it to prefix. | ||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||
| 254 | # if there's not already a device, /device had better look like | ||||||||||||||||||||||||||||
| 255 | # a PGPLOT device. | ||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||
| 257 | 0 | ▶ | if ( defined $device && !exists $DevMap{ lc $device } ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $device and not exists $PGPLOT::Device::DevMap{lc $device}
MC/DC0%0/2
defined $device and not exists $PGPLOT::Device::DevMap{lc $device}
defined $device
not exists $PGPLOT::Device::DevMap{lc $device}
Truth table0%0/3
A and not(B)
A= defined $deviceB= not exists $PGPLOT::Device::DevMap{lc $device}
| |||||||||||||||||||||||||||||
| 258 | 0 | ▶ | if ( defined $self->{device} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 259 | 0 | $prefix .= '/' . $device; | |||||||||||||||||||||||||||
| 260 | 0 | undef $device; | |||||||||||||||||||||||||||
| 261 | } | ||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||
| 263 | # no pre-existing device. make sure that the device is a real one | ||||||||||||||||||||||||||||
| 264 | else { | ||||||||||||||||||||||||||||
| 265 | 0 | _croak( "unknown PGPLOT device: $device\n" ); | |||||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||||
| 267 | } | ||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||
| 269 | # if device isn't defined, use the existing one for the object | ||||||||||||||||||||||||||||
| 270 | 0 | ▶ | $spec{device} = defined $device ? lc( $device ) : $self->{device}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 271 | 0 | $spec{devinfo} = $PGDevice{ $DevMap{ $spec{device} } }; | |||||||||||||||||||||||||||
| 272 | 0 | $spec{prefix} = $prefix; | |||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||
| 274 | 0 | ▶ | if ( $prefix ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 275 | # numeric (possibly autoincrement) | ||||||||||||||||||||||||||||
| 276 | 0 | ▶ | if ( $prefix =~ /^([+])?(\d+)?$/ ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 277 | 0 | ▶ | $spec{devn} = defined $2 ? $2 : 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||
| 279 | # if +, autoincrement device number | ||||||||||||||||||||||||||||
| 280 | # we use interpolation to handle this case | ||||||||||||||||||||||||||||
| 281 | 0 | ▶ | $spec{prefix} = defined $1 ? '${devn}' : $2; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||
| 284 | elsif ( defined $spec{device} ) { | ||||||||||||||||||||||||||||
| 285 | 0 | ▶ | if ( !$spec{devinfo}{inter} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 286 | my $ext | ||||||||||||||||||||||||||||
| 287 | = ( $spec{device} =~ m{^v?c?(ps)$}i ) | ||||||||||||||||||||||||||||
| 288 | ? ".$1" | ||||||||||||||||||||||||||||
| 289 | 0 | ▶ | : '.' . $spec{device}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||
| 291 | # make sure the appropriate suffix is in there | ||||||||||||||||||||||||||||
| 292 | 0 | $prefix =~ s/${ext}$//; | |||||||||||||||||||||||||||
| 293 | 0 | $prefix .= $ext; | |||||||||||||||||||||||||||
| 294 | 0 | $spec{prefix} = $prefix; | |||||||||||||||||||||||||||
| 295 | } | ||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||
| 297 | # we've got a situation here. an interactive device with a nonparseable | ||||||||||||||||||||||||||||
| 298 | # prefix. better bail | ||||||||||||||||||||||||||||
| 299 | else { | ||||||||||||||||||||||||||||
| 300 | 0 | _croak( | |||||||||||||||||||||||||||
| 301 | "error: interactive device with unparseable prefix: $spec\n" | ||||||||||||||||||||||||||||
| 302 | ); | ||||||||||||||||||||||||||||
| 303 | } | ||||||||||||||||||||||||||||
| 304 | } | ||||||||||||||||||||||||||||
| 305 | } | ||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||
| 307 | # only defined keys get through. makes it easier to override | ||||||||||||||||||||||||||||
| 308 | # things | ||||||||||||||||||||||||||||
| 309 | delete $spec{$_} | ||||||||||||||||||||||||||||
| 310 | 0 | ▶ | for grep { !defined $spec{$_} || '' eq $spec{$_} } keys %spec; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||
| 312 | 0 | %spec; | |||||||||||||||||||||||||||
| 313 | } | ||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||
| 326 | sub next { | ||||||||||||||||||||||||||||
| 327 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
next: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||
| 329 | 0 | $self->{last} = $self->_stringify; | |||||||||||||||||||||||||||
| 330 | 0 | $self->{devn}++; | |||||||||||||||||||||||||||
| 331 | 0 | $self->{last}; | |||||||||||||||||||||||||||
| 332 | } | ||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||
| 343 | sub current { | ||||||||||||||||||||||||||||
| 344 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
current: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||
| 346 | 0 | $self->_stringify; | |||||||||||||||||||||||||||
| 347 | } | ||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||
| 358 | sub last { | ||||||||||||||||||||||||||||
| 359 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
last: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 360 | 0 | $self->{last}; | |||||||||||||||||||||||||||
| 361 | } | ||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||
| 363 | sub _compare { | ||||||||||||||||||||||||||||
| 364 | 0 | ▶ | my ( $self, $other, $reverse ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_compare: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||
| 366 | 0 | ▶ | $reverse ? $other cmp $self->_stringify : $self->_stringify cmp $other; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 367 | } | ||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||
| 378 | sub is_const { | ||||||||||||||||||||||||||||
| 379 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
is_const: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 380 | defined $self->{prefix} | ||||||||||||||||||||||||||||
| 381 | ? ( $self->_stringify eq $self->{prefix} . '/' . $self->{device} ) | ||||||||||||||||||||||||||||
| 382 | 0 | ▶ | : 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 383 | } | ||||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||
| 397 | sub would_change { | ||||||||||||||||||||||||||||
| 398 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
would_change: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||
| 400 | 0 | ▶ | return defined $self->{last} ? $self->_stringify ne $self->{last} : 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 401 | } | ||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||
| 408 | |||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||
| 411 | sub is_interactive { | ||||||||||||||||||||||||||||
| 412 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
is_interactive: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||
| 414 | 0 | $self->{devinfo}{inter}; | |||||||||||||||||||||||||||
| 415 | } | ||||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||
| 426 | sub is_ephemeral { | ||||||||||||||||||||||||||||
| 427 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
is_ephemeral: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 428 | 0 | $self->{device} =~ /$ephemeral/; | |||||||||||||||||||||||||||
| 429 | } | ||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||
| 431 | |||||||||||||||||||||||||||||
| 432 | sub _stringify { | ||||||||||||||||||||||||||||
| 433 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
_stringify: not called CC=9 SCAR=42.5
| |||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||
| 435 | # handle interpolated values | ||||||||||||||||||||||||||||
| 436 | 0 | ▶ | my $prefix = defined $self->{prefix} ? $self->{prefix} : ''; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||
| 438 | # get calling package | ||||||||||||||||||||||||||||
| 439 | |||||||||||||||||||||||||||||
| 440 | 0 | my ( $fmt, $val ); | |||||||||||||||||||||||||||
| 441 | |||||||||||||||||||||||||||||
| 442 | ## no critic ( ProhibitNoStrict ); | ||||||||||||||||||||||||||||
| 443 | 3 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 444 | 0 | my $pkg = ( caller( 1 ) )[0]; | |||||||||||||||||||||||||||
| 445 | 0 | ▶ | 1 while $prefix =~ s/ \$\{ (\w+) (?::([^\}]+))? } / | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 446 | 0 | ▶ | $fmt = defined $2 ? $2 : '%s'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 447 | |||||||||||||||||||||||||||||
| 448 | $val = | ||||||||||||||||||||||||||||
| 449 | |||||||||||||||||||||||||||||
| 450 | # special: device id | ||||||||||||||||||||||||||||
| 451 | $1 eq 'devn' ? $self->{devn} : | ||||||||||||||||||||||||||||
| 452 | |||||||||||||||||||||||||||||
| 453 | # part of the user passed set of variables? | ||||||||||||||||||||||||||||
| 454 | exists $self->{vars}{$1} ? | ||||||||||||||||||||||||||||
| 455 | |||||||||||||||||||||||||||||
| 456 | # dereference it if it's a scalar ref, else use it directly | ||||||||||||||||||||||||||||
| 457 | ( 'SCALAR' eq ref $self->{vars}{$1} ? | ||||||||||||||||||||||||||||
| 458 | 0 | ▶ | ${$self->{vars}{$1}} : $self->{vars}{$1} ) : | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 459 | |||||||||||||||||||||||||||||
| 460 | # is it in the parent package? | ||||||||||||||||||||||||||||
| 461 | 0 | ▶ | defined ${*{"${pkg}::$1"}{SCALAR}} ? ${*{"${pkg}::$1"}{SCALAR}} : | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||
| 463 | # nothing | ||||||||||||||||||||||||||||
| 464 | undef; | ||||||||||||||||||||||||||||
| 465 | |||||||||||||||||||||||||||||
| 466 | 0 | ▶ | sprintf( $fmt, $val ) if defined $val; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 467 | /ex; | ||||||||||||||||||||||||||||
| 468 | |||||||||||||||||||||||||||||
| 469 | 0 | $prefix . '/' . $self->{device}; | |||||||||||||||||||||||||||
| 470 | } | ||||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||
| 472 | 3 | 1; | |||||||||||||||||||||||||||
| 473 | |||||||||||||||||||||||||||||
| 474 | # | ||||||||||||||||||||||||||||
| 475 | # This file is part of PGPLOT-Device | ||||||||||||||||||||||||||||
| 476 | # | ||||||||||||||||||||||||||||
| 477 | # This software is Copyright (c) 2017 by Smithsonian Astrophysical Observatory. | ||||||||||||||||||||||||||||
| 478 | # | ||||||||||||||||||||||||||||
| 479 | # This is free software, licensed under: | ||||||||||||||||||||||||||||
| 480 | # | ||||||||||||||||||||||||||||
| 481 | # The GNU General Public License, Version 3, June 2007 | ||||||||||||||||||||||||||||
| 482 | # | ||||||||||||||||||||||||||||
| 483 | |||||||||||||||||||||||||||||
| 484 | __END__ | ||||||||||||||||||||||||||||