| 1 | package CXC::Gnuplot::V1::LiteralDataValue; | ||
| 2 | |||
| 3 | # ABSTRACT: a literal data value, either numeric or a date | ||
| 4 | |||
| 5 | 2 | ▶ | use v5.38; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | 2 | ▶ | use Object::Pad 0.821; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 7 | |||
| 8 | our $VERSION = 'v0.29.3'; | ||
| 9 | |||
| 10 | |||
| 11 | class CXC::Gnuplot::V1::LiteralDataValue : isa(CXC::Gnuplot::V1::Base) | ||
| 12 | does( CXC::Gnuplot::V1::Role::Clone ); | ||
| 13 | |||
| 14 | no namespace::clean; | ||
| 15 | |||
| 16 | use Scalar::Util 'looks_like_number'; | ||
| 17 | use Ref::Util 'is_ref'; | ||
| 18 | use experimental 'builtin'; | ||
| 19 | use builtin 'true'; | ||
| 20 | |||
| 21 | use namespace::clean; | ||
| 22 | |||
| 23 | use overload q{""} => \&stringify, bool => sub { true }, fallback => true; | ||
| 24 | |||
| 25 | my sub croak { | ||
| 26 | require Carp; | ||
| 27 | goto \&Carp::croak; | ||
| 28 | } | ||
| 29 | |||
| 30 | |||
| 31 | |||
| 32 | |||
| 33 | |||
| 34 | field $value : param : reader; | ||
| 35 | field $string; | ||
| 36 | |||
| 37 | ADJUST { | ||
| 38 | |||
| 39 | is_ref( $value ) | ||
| 40 | and croak( 'value must be a scalar' ); | ||
| 41 | |||
| 42 | require B; | ||
| 43 | $string = looks_like_number( $value ) ? $value : B::cstring( $value ); | ||
| 44 | } | ||
| 45 | |||
| 46 | |||
| 47 | |||
| 48 | |||
| 49 | |||
| 50 | |||
| 51 | |||
| 52 | |||
| 53 | |||
| 54 | |||
| 55 | |||
| 56 | |||
| 57 | |||
| 58 | |||
| 59 | method BUILDARGS : common (@args ) { | ||
| 60 | return ( value => $args[0] ) if @args == 1 && !is_ref( $args[0] ); | ||
| 61 | return $class->SUPER::BUILDARGS( @args ); | ||
| 62 | } | ||
| 63 | |||
| 64 | |||
| 65 | |||
| 66 | |||
| 67 | |||
| 68 | |||
| 69 | |||
| 70 | |||
| 71 | |||
| 72 | |||
| 73 | method to_hash { | ||
| 74 | $value; | ||
| 75 | } | ||
| 76 | |||
| 77 | |||
| 78 | |||
| 79 | |||
| 80 | |||
| 81 | |||
| 82 | |||
| 83 | |||
| 84 | |||
| 85 | |||
| 86 | |||
| 87 | method stringify { | ||
| 88 | return $string; | ||
| 89 | } | ||
| 90 | |||
| 91 | |||
| 92 | 1; | ||
| 93 | |||
| 94 | __END__ | ||