summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitignore3
-rw-r--r--Makefile.PL10
-rw-r--r--Stash.xs26
-rw-r--r--dist.ini6
-rw-r--r--lib/Package/Stash.pm30
5 files changed, 58 insertions, 17 deletions
diff --git a/.gitignore b/.gitignore
index 478a475..92100a6 100644
--- a/.gitignore
+++ b/.gitignore
@@ -10,3 +10,6 @@ MANIFEST.bak
*.sw[po]
.build
Package-Stash-*
+*.bs
+*.c
+*.o
diff --git a/Makefile.PL b/Makefile.PL
new file mode 100644
index 0000000..9791d1c
--- /dev/null
+++ b/Makefile.PL
@@ -0,0 +1,10 @@
+use ExtUtils::MakeMaker;
+
+# NOTE:
+# this is a very simple Makefile.PL i only use to build the distribution locally
+# while working on it the real Makefile.PL, with all required information like
+# dependencies, is generated later by Dist::Zilla
+
+WriteMakefile(
+ NAME => 'Package::Stash',
+);
diff --git a/Stash.xs b/Stash.xs
new file mode 100644
index 0000000..879d7ac
--- /dev/null
+++ b/Stash.xs
@@ -0,0 +1,26 @@
+#include "EXTERN.h"
+#include "perl.h"
+#include "XSUB.h"
+
+MODULE = Package::Stash PACKAGE = Package::Stash
+
+SV*
+new(class, package_name)
+ char *class
+ SV *package_name
+ INIT:
+ HV *instance;
+ HV *namespace;
+ CODE:
+ if (!SvPOK(package_name))
+ croak("The constructor argument must be the name of a package");
+
+ instance = newHV();
+
+ hv_store(instance, "name", 4, package_name, 0);
+ namespace = gv_stashpv(SvPV_nolen(package_name), GV_ADD);
+ hv_store(instance, "namespace", 9, newRV((SV*)namespace), 0);
+
+ RETVAL = sv_bless(newRV((SV*)instance), gv_stashpv(class, 0));
+ OUTPUT:
+ RETVAL
diff --git a/dist.ini b/dist.ini
index 8b69822..9203c25 100644
--- a/dist.ini
+++ b/dist.ini
@@ -14,3 +14,9 @@ Scalar::Util = 0
[Prereqs / TestRequires]
Test::Fatal = 0
Test::More = 0.88
+
+; we maintain a Makefile.PL in the repository to be able to work without dzil,
+; but for the distribution we let dzil generate a Makefile.PL with the proper
+; dependencies and such
+[PruneFiles]
+filenames = Makefile.PL
diff --git a/lib/Package/Stash.pm b/lib/Package/Stash.pm
index 4f1db68..871889a 100644
--- a/lib/Package/Stash.pm
+++ b/lib/Package/Stash.pm
@@ -6,6 +6,18 @@ use warnings;
use Carp qw(confess);
use Scalar::Util qw(reftype);
use Symbol;
+
+use XSLoader;
+XSLoader::load(
+ __PACKAGE__,
+ # we need to be careful not to touch $VERSION at compile time, otherwise
+ # DynaLoader will assume it's set and check against it, which will cause
+ # fail when being run in the checkout without dzil having set the actual
+ # $VERSION
+ exists $Package::Stash::{VERSION}
+ ? ${ $Package::Stash::{VERSION} } : (),
+);
+
# before 5.12, assigning to the ISA glob would make it lose its magical ->isa
# powers
use constant BROKEN_ISA_ASSIGNMENT => ($] < 5.012);
@@ -35,22 +47,6 @@ argument.
=cut
-sub new {
- my $class = shift;
- my ($package) = @_;
- my $namespace;
- {
- no strict 'refs';
- # supposedly this caused a bug in earlier perls, but I can't reproduce
- # it, so re-enabling the caching
- $namespace = \%{$package . '::'};
- }
- return bless {
- 'package' => $package,
- 'namespace' => $namespace,
- }, $class;
-}
-
=method name
Returns the name of the package that this object represents.
@@ -58,7 +54,7 @@ Returns the name of the package that this object represents.
=cut
sub name {
- return $_[0]->{package};
+ return $_[0]->{name};
}
=method namespace