Commits

Konstantin Baierer committed 05b0f42

resources can be probed is their 'rdf_about' was auto-generated

Comments (0)

Files changed (3)

lib/MooseX/Semantic/Role/Resource.pm

     handles => [qw( is_blank is_resource )],
 );
 sub _build_rdf_about {
+    my $self = shift;
     # XXX should Resources be by default blank nodes or have a UUID URI?
+    $self->_is_auto_generated(1);
     TrineResource->coerce(sprintf('urn:uuid:%s', Data::UUID->new->create_str));
 }
 
+has _is_auto_generated => (
+    is => 'rw',
+    isa => 'Bool',
+    init_arg => undef,
+    default => 0,
+    lazy => 1,
+);
+
+sub is_auto_generated {
+    my $self = shift;
+    # make sure rdf_about has been initialized lazily
+    $self->rdf_about;
+    return $self->_is_auto_generated;
+}
+
 1;
 
 =head1 METHODS
+#=======================================================================
+# rdf_resource.t
+#=======================================================================
+use common::sense;
+use Test::Most tests => 1;
+use Data::Dumper;
+{
+    package SemTest;
+    use Moose;
+    with qw(MooseX::Semantic::Role::Resource);
+}
+
+my $t1 = SemTest->new();
+my $t2 = SemTest->new(
+    rdf_about => 'foo',
+);
+# warn Dumper $t->rdf_about;
+ok( $t1->is_auto_generated, 't1 has auto-generated ID' );
+ok( ! $t2->is_auto_generated, 't1 has explicit rdf_about' );
+
+
+
+
 use strict;
 use warnings;
 use Test::More
-    skip_all => 'no reason'
+    # skip_all => 'no reason'
+    tests => 1
     ; 
 use Test::Moose;
 use Data::Dumper;
 use URI;
 
 my $p = MooseX::Semantic::Test::Person->new;
-done_testing;