| 1 | package X11::XRandR::Frequency; | ||
| 2 | |||
| 3 | # ABSTRACT: A Frequency value | ||
| 4 | |||
| 5 | 1 | ▶ | use Types::Standard qw[ Enum ]; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | 1 | ▶ | use Types::Common::Numeric qw[ PositiveNum ]; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | |||
| 8 | 1 | ▶ | use Moo; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 9 | 1 | ▶ | use namespace::clean; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 10 | 1 | ▶ | use MooX::StrictConstructor; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 11 | |||
| 12 | 1 | our $VERSION = '0.01'; | |
| 13 | |||
| 14 | #pod =attr value | ||
| 15 | #pod | ||
| 16 | #pod The value | ||
| 17 | #pod | ||
| 18 | #pod =cut | ||
| 19 | |||
| 20 | |||
| 21 | 1 | ▶ | use overload '""' => \&to_string; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 22 | 1 | has value => ( | |
| 23 | is => 'ro', | ||
| 24 | isa => PositiveNum, | ||
| 25 | required => 1, | ||
| 26 | ); | ||
| 27 | |||
| 28 | #pod =attr unit | ||
| 29 | #pod | ||
| 30 | #pod The unit. May be C<MHz>, C<KHz>, C<Hz>. | ||
| 31 | #pod | ||
| 32 | #pod =cut | ||
| 33 | |||
| 34 | 1 | has unit => ( | |
| 35 | is => 'ro', | ||
| 36 | isa => Enum [qw( MHz KHz Hz )], | ||
| 37 | required => 1, | ||
| 38 | ); | ||
| 39 | |||
| 40 | #pod =method to_Hz | ||
| 41 | #pod | ||
| 42 | #pod Convert the value to Hz. | ||
| 43 | #pod | ||
| 44 | #pod =cut | ||
| 45 | |||
| 46 | 1 | my %to_Hz = ( | |
| 47 | MHz => 1e6, | ||
| 48 | KHz => 1e3, | ||
| 49 | Hz => 1, | ||
| 50 | ); | ||
| 51 | |||
| 52 | 0 | ▶ | sub to_Hz { |
|
Subroutine
to_Hz: not called CC=1 SCAR=6.9
Pod
documented
| |||
| 53 | |||
| 54 | 0 | my $self = shift; | |
| 55 | |||
| 56 | 0 | return $self->value * $to_Hz{ $self->unit }; | |
| 57 | } | ||
| 58 | |||
| 59 | |||
| 60 | #pod =method to_string | ||
| 61 | #pod | ||
| 62 | #pod Return a string rendition of the object just as B<xrandr> would. | ||
| 63 | #pod | ||
| 64 | #pod =cut | ||
| 65 | |||
| 66 | 0 | ▶ | sub to_string { |
|
Subroutine
to_string: not called CC=1 SCAR=6.9
Pod
documented
| |||
| 67 | 0 | sprintf( "%f%s", $_[0]->value, $_[0]->unit ); | |
| 68 | } | ||
| 69 | |||
| 70 | 1 | 1; | |
| 71 | |||
| 72 | # | ||
| 73 | # This file is part of X11-XRandR | ||
| 74 | # | ||
| 75 | # This software is Copyright (c) 2018 by Diab Jerius. | ||
| 76 | # | ||
| 77 | # This is free software, licensed under: | ||
| 78 | # | ||
| 79 | # The GNU General Public License, Version 3, June 2007 | ||
| 80 | # | ||
| 81 | |||
| 82 | __END__ | ||