blib/lib/SDL2/version.pm untested

filter: Statementstmt 0.0% 0 / 32 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 5 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 40 CC 2 SCAR 12.0
CC
2
Cov
0%
_ver
6.0
BEGIN
2.0
BEGIN
2.0
CRAP 3.3
1 package SDL2::version 0.01 {
2 use SDL2::Utils;
3 use experimental 'signatures';
4 #
5 use SDL2::stdinc;
6 #
7 package SDL2::Version {
8 use SDL2::Utils;
9 our $TYPE = has major => 'uint8', minor => 'uint8', patch => 'uint8';
10 };
11  
12 sub _ver() {
13 CORE::state $version;
14 if ( !defined $version ) {
15 $version = SDL2::Version->new();
16 SDL2::FFI::SDL_VERSION($version);
17 }
18 $version;
19 }
20 define version => [
21 [ SDL_MAJOR_VERSION => sub () { SDL2::version::_ver()->major } ],
22 [ SDL_MINOR_VERSION => sub () { SDL2::version::_ver()->minor } ],
23 [ SDL_PATCHLEVEL => sub () { SDL2::version::_ver()->patch } ],
24 [ SDL_VERSION => sub ($version) { SDL2::FFI::SDL_GetVersion($version); } ],
25 [ SDL_VERSIONNUM => sub ( $X, $Y, $Z ) { ( ($X) * 1000 + ($Y) * 100 + ($Z) ) } ],
26 [ SDL_COMPILEDVERSION => sub () {
27 SDL2::FFI::SDL_VERSIONNUM(
28 SDL2::FFI::SDL_MAJOR_VERSION(),
29 SDL2::FFI::SDL_MINOR_VERSION(),
30 SDL2::FFI::SDL_PATCHLEVEL()
31 );
32 }
33 ],
34 [ SDL_VERSION_ATLEAST => sub ( $X, $Y, $Z ) {
35 ( SDL2::FFI::SDL_COMPILEDVERSION() >= SDL2::FFI::SDL_VERSIONNUM( $X, $Y, $Z ) )
36 }
37 ]
38 ];
39 attach version =>
40 { SDL_GetVersion => [ ['SDL_Version'] ], SDL_GetRevision => [ [], 'string' ], };
41  
42 =encoding utf-8
43  
44 =head1 NAME
45  
46 SDL2::version - Information About the Version of SDL in Use
47  
48 =head1 SYNOPSIS
49  
50 use SDL2 qw[:version];
51 SDL_GetVersion( my $ver = SDL2::version->new );
52 CORE::say sprintf 'SDL version %d.%d.%d', $ver->major, $ver->minor, $ver->patch;
53  
54 =head1 DESCRIPTION
55  
56 SDL2::version represents the library's version as three levels: major, minor,
57 and patch level.
58  
59 =head1 Functions
60  
61 These may be imported with the <:version> tag.
62  
63 =head2 C<SDL_VERSION( ... )>
64  
65 Macro to determine SDL version program was compiled against.
66  
67 This macro fills in a SDL_version structure with the version of the library you
68 compiled against. This is determined by what header the compiler uses. Note
69 that if you dynamically linked the library, you might have a slightly newer or
70 older version at runtime. That version can be determined with SDL_GetVersion(),
71 which, unlike SDL_VERSION(), is not a macro.
72  
73 Expected parameters include:
74  
75 =over
76  
77 =item C<x> - a pointer to a L<SDL2::Version> struct to initialize
78  
79 =back
80  
81 =head2 C<SDL_VERSIONNUM( ... )>
82  
83 This macro turns the version numbers into a numeric value:
84  
85 (1,2,3) -> (1203)
86  
87 This assumes that there will never be more than 100 patchlevels.
88  
89 Expected parameters include:
90  
91 =over
92  
93 =item C<major>
94  
95 =item C<minor>
96  
97 =item C<patch>
98  
99 =back
100  
101 Returns an integer.
102  
103 =head2 C<SDL_VERSION_ATLEAST( )>
104  
105 Evaluates to true if compiled with SDL at least C<major.minor.patch>.
106  
107 if ( SDL_VERSION_ATLEAST( 2, 0, 15 ) ) {
108 # Some feature that requires 2.0.15+
109 }
110  
111 Expected parameters include:
112  
113 =over
114  
115 =item C<major>
116  
117 =item C<minor>
118  
119 =item C<patch>
120  
121 =back
122  
123 Returns a boolean value.
124  
125 =head2 C<GetVersion( ... )>
126  
127 Get the version of SDL that is linked against your program.
128  
129 SDL_GetVersion( my $version_ = SDL2::Version->new() );
130  
131 If you are linking to SDL dynamically, then it is possible that the current
132 version will be different than the version you compiled against. This function
133 returns the current version, while L<< C<SDL_VERSION( ... )>|/C<SDL_VERSION(
134 ... )> >> is a macro that tells you what version you compiled with.
135  
136 This function may be called safely at any time, even before C<SDL_Init( ... )>.
137  
138 Expected parameters include:
139  
140 =over
141  
142 =item C<ver> - the L<SDL2::Version> structure that contains the version information
143  
144 =back
145  
146 =head2 C<SDL_GetRevision( )>
147  
148 Get the code revision of SDL that is linked against your program.
149  
150 This value is the revision of the code you are linked with and may be different
151 from the code you are compiling with, which is found in the upstream constant
152 C<SDL_REVISION>.
153  
154 The revision is arbitrary string (a hash value) uniquely identifying the exact
155 revision of the SDL library in use, and is only useful in comparing against
156 other revisions. It is NOT an incrementing number.
157  
158 If SDL wasn't built from a git repository with the appropriate tools, this will
159 return an empty string.
160  
161 Prior to SDL 2.0.16, before development moved to GitHub, this returned a hash
162 for a Mercurial repository.
163  
164 You shouldn't use this function for anything but logging it for debugging
165 purposes. The string is not intended to be reliable in any way.
166  
167 Returns an arbitrary string, uniquely identifying the exact revision of the SDL
168 library in use.
169  
170 =head1 Defined Values
171  
172 These may be imported with the <:version> tag.
173  
174 =over
175  
176 =item C<SDL_MAJOR_VERSION>
177  
178 =item C<SDL_MINOR_VERSION>
179  
180 =item C<SDL_PATCHLEVEL>
181  
182 =item C<SDL_COMPILEDVERSION> - Version number for the current SDL version
183  
184 =back
185  
186 =head1 LICENSE
187  
188 Copyright (C) Sanko Robinson.
189  
190 This library is free software; you can redistribute it and/or modify it under
191 the terms found in the Artistic License 2. Other copyrights, terms, and
192 conditions may apply to data transmitted through this module.
193  
194 =head1 AUTHOR
195  
196 Sanko Robinson E<lt>sanko@cpan.orgE<gt>
197  
198 =begin stopwords
199  
200 patchlevels
201  
202 =end stopwords
203  
204 =cut
205  
206 };
207 1;