diff options
author | Jesse Luehrs <doy@tozt.net> | 2010-11-11 22:14:56 -0600 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2010-11-12 03:20:44 -0600 |
commit | 59017825dd984a30f69bec25890d1ffceaf30e04 (patch) | |
tree | be633cf9ad0e6c511ec9b9c298178e135c924b45 | |
parent | d1f721b320d72e83c0cb24c45fe9995a6dcf29c2 (diff) | |
download | package-stash-xs-59017825dd984a30f69bec25890d1ffceaf30e04.tar.gz package-stash-xs-59017825dd984a30f69bec25890d1ffceaf30e04.zip |
start the conversion to xs
-rw-r--r-- | .gitignore | 3 | ||||
-rw-r--r-- | Makefile.PL | 10 | ||||
-rw-r--r-- | Stash.xs | 26 | ||||
-rw-r--r-- | dist.ini | 6 | ||||
-rw-r--r-- | lib/Package/Stash.pm | 30 |
5 files changed, 58 insertions, 17 deletions
@@ -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 @@ -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 |