File Coverage

blib/lib/Acme/ExtUtils/XSOne/Test/Calculator.pm
Criterion Covered Total %
statement 8 8 100.0
branch n/a
condition n/a
subroutine 3 3 100.0
pod n/a
total 11 11 100.0


line stmt bran cond sub pod time code
1             package Acme::ExtUtils::XSOne::Test::Calculator;
2              
3 3     3   585642 use 5.008003;
  3         13  
4 3     3   18 use strict;
  3         7  
  3         99  
5 3     3   13 use warnings;
  3         5  
  3         541  
6              
7             our $VERSION = '0.01';
8              
9             require XSLoader;
10             XSLoader::load('Acme::ExtUtils::XSOne::Test::Calculator', $VERSION);
11              
12             =head1 NAME
13              
14             Acme::ExtUtils::XSOne::Test::Calculator - A scientific calculator demonstrating ExtUtils::XSOne
15              
16             =head1 VERSION
17              
18             Version 0.01
19              
20             =head1 SYNOPSIS
21              
22             # Import functions directly from submodules
23             use Acme::ExtUtils::XSOne::Test::Calculator::Basic qw(add subtract multiply divide);
24             use Acme::ExtUtils::XSOne::Test::Calculator::Scientific qw(power sqrt_val);
25             use Acme::ExtUtils::XSOne::Test::Calculator::Trig qw(sin_val cos_val deg_to_rad);
26             use Acme::ExtUtils::XSOne::Test::Calculator::Memory qw(store recall ans clear);
27              
28             # Basic arithmetic
29             my $sum = add(2, 3); # 5
30             my $diff = subtract(10, 4); # 6
31             my $prod = multiply(3, 4); # 12
32             my $quot = divide(15, 3); # 5
33              
34             # Scientific functions
35             my $pow = power(2, 10); # 1024
36             my $sqrt = sqrt_val(16); # 4
37              
38             # Trigonometry
39             my $sin = sin_val(deg_to_rad(90)); # 1.0
40              
41             # Memory functions (shared state across all submodules!)
42             store(0, 42);
43             my $val = recall(0); # 42
44             my $last = ans(); # last result from any calculation
45             clear(); # reset all memory and history
46              
47             # Or use fully qualified names without importing
48             use Acme::ExtUtils::XSOne::Test::Calculator;
49              
50             my $pi = Acme::ExtUtils::XSOne::Test::Calculator::pi();
51             my $e = Acme::ExtUtils::XSOne::Test::Calculator::e();
52              
53             =head1 DESCRIPTION
54              
55             Acme::ExtUtils::XSOne::Test::Calculator is a demonstration module showing how to use
56             L to create a multi-file XS module where all
57             submodules share C-level state.
58              
59             =head1 PACKAGES
60              
61             All submodules support importing functions by name via C.
62              
63             =over 4
64              
65             =item * L
66              
67             Basic arithmetic: C, C, C, C, C,
68             C, C, C, C, C
69              
70             =item * L
71              
72             Scientific operations: C, C, C, C,
73             C, C, C, C, C,
74             C, C, C, C, C
75              
76             =item * L
77              
78             Trigonometry: C, C, C, C, C,
79             C, C, C, C, C,
80             C, C, C, C, C
81              
82             =item * L
83              
84             Memory and history: C, C, C, C, C,
85             C, C, C,
86             C, C, C, C
87              
88             =back
89              
90             =head1 SHARED STATE
91              
92             A key feature of this module is that all submodules share C-level state.
93             This means:
94              
95             =over 4
96              
97             =item * The C function returns the last result from I calculation
98              
99             =item * Memory slots are accessible from all submodules
100              
101             =item * Calculation history records operations from all submodules
102              
103             =back
104              
105             This is made possible by L, which combines multiple XS
106             files into a single shared library.
107              
108             =head1 AUTHOR
109              
110             lnation Eemail@lnation.orgE
111              
112             =head1 LICENSE AND COPYRIGHT
113              
114             This software is Copyright (c) 2026 by lnation.
115              
116             This is free software, licensed under:
117              
118             The Artistic License 2.0 (GPL Compatible)
119              
120             =cut
121              
122             1;