Permalink
Browse files

Add Magic-Example

  • Loading branch information...
1 parent ce26cb9 commit e44557bbf135ede9902d6733ef23b93178049b95 @gfx committed Sep 9, 2009
View
@@ -0,0 +1,15 @@
+.*
+!.gitignore
+!.shipit
+*.o
+*.obj
+*.bs
+Makefile*
+!Makefile.PL
+*blib
+META.yml
+inc/
+MANIFEST
+*.out
+ppport.h
+Magic-Example-*
View
@@ -0,0 +1,4 @@
+Revision history for Perl extension Magic::Example
+
+0.001 Tue Sep 8 15:58:46 2009
+ - original version; created by Module::Setup
View
@@ -0,0 +1,29 @@
+#define PERL_NO_GET_CONTEXT
+#include <EXTERN.h>
+#include <perl.h>
+#include <XSUB.h>
+
+#ifdef USE_PPPORT
+#include "ppport.h"
+#endif
+
+static void
+do_something_to_hv(HV* const hv PERL_UNUSED_DECL){
+ NOOP;
+}
+
+#define do_something_to_hashref_wrong do_something_to_hv
+#define do_something_to_hashref_correct do_something_to_hv
+
+typedef HV* HVREF;
+
+MODULE = Magic::Example PACKAGE = Magic::Example
+
+PROTOTYPES: DISABLE
+
+void
+do_something_to_hashref_wrong(HV* hv)
+
+void
+do_something_to_hashref_correct(HVREF hv)
+
@@ -0,0 +1,28 @@
+#!include_default
+
+# skip dot files
+^\.
+
+# skip author's files
+\bauthor\b
+
+# skip object files
+Example\.c$
+\.o(?:bj)?$
+\.bs$
+\.def$
+
+\.out$
+
+# skip devel-cover stuff
+\.gcda$
+\.gcno$
+\.gcov$
+cover_db/
+
+# skip nytprof stuff
+nytprof/
+\.out$
+
+Magic-Example-
+ppport\.h$
View
@@ -0,0 +1,25 @@
+use strict;
+use warnings;
+use inc::Module::Install;
+
+all_from 'lib/Magic/Example.pm';
+
+use_ppport 3.19;
+cc_warnings;
+
+test_requires 'Test::More' => 0.88; # done_testing()
+
+tests 't/*.t';
+author_tests 'xt';
+
+auto_set_repository() if -d '.git';
+
+clean_files qw(
+ Magic-Example-* *.stackdump
+ *.gcda *.gcno *.gcov
+ nytprof *.out
+ cover_db
+);
+
+WriteAll check_nmake => 0;
+
View
@@ -0,0 +1,27 @@
+This is Perl module Magic::Example.
+
+INSTALLATION
+
+Magic::Example installation is straightforward. If your CPAN shell is set up,
+you should just be able to do
+
+ $ cpan Magic::Example
+
+Download it, unpack it, then build it as per the usual:
+
+ $ perl Makefile.PL
+ $ make && make test
+
+Then install it:
+
+ $ make install
+
+DOCUMENTATION
+
+Magic::Example documentation is available as in POD. So you can do:
+
+ $ perldoc Magic::Example
+
+to read the documentation online with your favorite pager.
+
+Goro Fuji (gfx)
@@ -0,0 +1,77 @@
+package Magic::Example;
+
+use 5.008_001;
+use strict;
+use warnings;
+
+our $VERSION = '0.001';
+
+use XSLoader;
+XSLoader::load(__PACKAGE__, $VERSION);
+
+use base qw(Exporter);
+our @EXPORT = qw(do_something_to_hashref_wrong do_something_to_hashref_correct);
+
+
+1;
+__END__
+
+=head1 NAME
+
+Magic::Example -
+
+=head1 VERSION
+
+This document describes Magic::Example version 0.001.
+
+=head1 SYNOPSIS
+
+ use Magic::Example;
+
+=head1 DESCRIPTION
+
+Magic::Example provides
+
+=head1 INTERFACE
+
+=head2 Class methods
+
+=over 4
+
+=item *
+
+=back
+
+=head2 Instance methods
+
+=over 4
+
+=item *
+
+=back
+
+
+=head1 DEPENDENCIES
+
+Perl 5.8.1 or later, and a C compiler.
+
+=head1 BUGS
+
+No bugs have been reported.
+
+Please report any bugs or feature requests to the author.
+
+=head1 SEE ALSO
+
+=head1 AUTHOR
+
+Goro Fuji (gfx) E<lt>gfuji(at)cpan.orgE<gt>
+
+=head1 LICENSE AND COPYRIGHT
+
+Copyright (c) 2009, Goro Fuji (gfx). Some rights reserved.
+
+This library is free software; you can redistribute it and/or modify
+it under the same terms as Perl itself.
+
+=cut
@@ -0,0 +1,9 @@
+#!perl -w
+
+use strict;
+use Test::More tests => 1;
+
+BEGIN { use_ok 'Magic::Example' }
+
+diag "Testing Magic::Example/$Magic::Example::VERSION";
+
View
@@ -0,0 +1,23 @@
+#!perl -w
+
+use strict;
+use Test::More;
+use Test::Exception;
+
+use Magic::Example;
+
+use Tie::Scalar;
+
+tie my $tied_scalar, 'Tie::StdScalar', {};
+
+lives_ok{
+ do_something_to_hashref_wrong($tied_scalar);
+} 'bad example';
+
+
+lives_ok{
+ do_something_to_hashref_correct($tied_scalar);
+} 'good example';
+
+
+done_testing;
View
@@ -0,0 +1,16 @@
+HVREF T_HVREF_MG
+
+INPUT
+T_HVREF_MG
+ {
+ SV* const _arg = $arg;
+ SvGETMAGIC(_arg);
+ if (SvROK(_arg) && SvTYPE(SvRV(_arg))==SVt_PVHV)
+ $var = (HV*)SvRV(_arg);
+ else
+ Perl_croak(aTHX_ \"%s: %s is not a hash reference\",
+ ${$ALIAS?\q[GvNAME(CvGV(cv))]:\qq[\"$pname\"]},
+ \"$var\");
+ }
+
+OUTPUT

0 comments on commit e44557b

Please sign in to comment.