*.sw[po]
.build
Package-Stash-*
+*.bs
+*.c
+*.o
--- /dev/null
+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',
+);
--- /dev/null
+#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
[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
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);
=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.
=cut
sub name {
- return $_[0]->{package};
+ return $_[0]->{name};
}
=method namespace