Permalink
Browse files

improve tests for message

  • Loading branch information...
1 parent 1bf5883 commit 4118f4c288b8e01a653395b3a85ba4e2fde64ba4 @zigorou committed Sep 2, 2009
@@ -12,32 +12,50 @@ for (
__PACKAGE__->mk_classdata($_);
}
+__PACKAGE__->element_fields([]);
+__PACKAGE__->element_to_field_map(+{});
+__PACKAGE__->field_to_element_map(+{});
__PACKAGE__->namespaces(
+{
'http://ns.opensocial.org/2008/opensocial' => 'os',
+ 'http://opensocial.org/2008/opensocialapi' => 'osapi',
'http://www.w3.org/2005/Atom' => 'atom',
'http://a9.com/-/spec/opensearch/1.1' => 'osearch',
},
);
+__PACKAGE__->field_to_namespace_map(+{});
sub setup {
my ( $class, @element_fields ) = @_;
- $class->element_fields( [ map { $_->{field} } @element_fields ] );
+ $class->element_fields( [ ( @{$class->element_fields}, map { $_->{field} } @element_fields ) ] );
$class->element_to_field_map(
+{
- map { @$_{qw/typemap field/} }
- grep { exists $_->{typemap} } @element_fields
+ %{$class->element_to_field_map},
+ (
+ map { @$_{qw/typemap field/} }
+ grep { exists $_->{typemap} } @element_fields
+ ),
}
);
$class->field_to_element_map(
+{
- map { @$_{qw/field typemap/} }
- grep { exists $_->{typemap} } @element_fields
+ %{$class->field_to_element_map},
+ (
+ map { @$_{qw/field typemap/} }
+ grep { exists $_->{typemap} } @element_fields
+ ),
}
);
$class->field_to_namespace_map(
- +{ map { ( $_->{field}, $_->{namespace} ) } @element_fields } );
+ +{
+ %{ $class->field_to_namespace_map },
+ (
+ map { ( $_->{field}, $_->{namespace} ) }
+ @element_fields
+ )
+ },
+ );
return map {
my $attr = $_;
@@ -6,9 +6,8 @@ use JSON::Any qw(DWIW XS Syck JSON);
use Data::Util qw(is_array_ref is_hash_ref);
use DateTime::Format::ISO8601;
use Data::OpenSocial::Types;
-
-# use Module::Load;
-# use Module::Loaded;
+use Module::Load;
+use Module::Loaded;
sub format {
my ( $class, $object ) = @_;
@@ -96,8 +95,6 @@ sub parse {
sub parse_object {
my ( $class, $class_type, $object ) = @_;
- load $class_type unless ( is_loaded $class_type);
-
if ( UNIVERSAL::isa( $class_type, 'Data::OpenSocial::Appdata' )
&& !exists $object->{entry} )
{
@@ -111,6 +108,8 @@ sub parse_object {
}
}
+ load $class_type unless (is_loaded($class_type));
+
my %data;
for my $element ( keys %$object ) {
my $field = $class_type->element_to_field($element);
@@ -36,6 +36,7 @@ do {
+{
namespace => 'http://ns.opensocial.org/2008/opensocial',
field => 'thumbnail_url',
+ typemap => 'thumbnailUrl',
is => 'rw',
isa => 'Str',
required => 0,
@@ -71,20 +72,23 @@ do {
+{
namespace => 'http://ns.opensocial.org/2008/opensocial',
field => 'album_id',
+ typemap => 'albumId',
is => 'rw',
isa => 'Str',
required => 0,
},
+{
namespace => 'http://ns.opensocial.org/2008/opensocial',
field => 'file_size',
+ typemap => 'fileSize',
is => 'rw',
isa => 'Int',
required => 0,
},
+{
namespace => 'http://ns.opensocial.org/2008/opensocial',
field => 'start_time',
+ typemap => 'startTime',
is => 'rw',
isa => 'DateTime',
required => 0,
@@ -99,20 +103,23 @@ do {
+{
namespace => 'http://ns.opensocial.org/2008/opensocial',
field => 'num_votes',
+ typemap => 'numVotes',
is => 'rw',
isa => 'Int',
required => 0,
},
+{
namespace => 'http://ns.opensocial.org/2008/opensocial',
field => 'num_comments',
+ typemap => 'numComments',
is => 'rw',
isa => 'Int',
required => 0,
},
+{
namespace => 'http://ns.opensocial.org/2008/opensocial',
field => 'num_views',
+ typemap => 'numViews',
is => 'rw',
isa => 'Int',
required => 0,
@@ -127,13 +134,15 @@ do {
+{
namespace => 'http://ns.opensocial.org/2008/opensocial',
field => 'tagged_people',
+ typemap => 'taggedPeople',
is => 'rw',
isa => 'Str',
required => 0,
},
+{
namespace => 'http://ns.opensocial.org/2008/opensocial',
field => 'mime_type',
+ typemap => 'mimeType',
is => 'rw',
isa => 'Str',
required => 0,
@@ -142,7 +151,7 @@ do {
namespace => 'http://ns.opensocial.org/2008/opensocial',
field => 'type',
is => 'rw',
- isa => 'MediaItemType',
+ isa => 'OpenSocial.MediaItemType',
required => 0,
},
+{
@@ -4,7 +4,11 @@ use Any::Moose;
use Any::Moose ( 'X::Types::DateTime' => [qw/DateTime/], );
use Any::Moose 'X::AttributeHelpers';
-use Data::OpenSocial::Types qw(OpenSocial.Url);
+use Data::OpenSocial::Types qw(
+ OpenSocial.Url
+ OpenSocial.Url.Collection
+ OpenSocial.MessageType
+);
extends 'Data::OpenSocial::Base';
@@ -20,6 +24,7 @@ do {
+{
namespace => 'http://ns.opensocial.org/2008/opensocial',
field => 'body_id',
+ typemap => 'bodyId',
is => 'rw',
isa => 'Str',
required => 0,
@@ -34,6 +39,7 @@ do {
+{
namespace => 'http://ns.opensocial.org/2008/opensocial',
field => 'title_id',
+ typemap => 'titleId',
is => 'rw',
isa => 'Str',
required => 0,
@@ -49,19 +55,21 @@ do {
namespace => 'http://ns.opensocial.org/2008/opensocial',
field => 'recipients',
is => 'rw',
- isa => 'Str',
+ isa => 'ArrayRef[Str]',
required => 0,
},
+{
namespace => 'http://ns.opensocial.org/2008/opensocial',
field => 'sender_id',
+ typemap => 'senderId',
is => 'rw',
isa => 'Str',
required => 0,
},
+{
namespace => 'http://ns.opensocial.org/2008/opensocial',
field => 'time_sent',
+ typemap => 'timeSent',
is => 'rw',
isa => 'DateTime',
required => 0,
@@ -70,6 +78,7 @@ do {
+{
namespace => 'http://ns.opensocial.org/2008/opensocial',
field => 'in_reply_to',
+ typemap => 'inReplyTo',
is => 'rw',
isa => 'Str',
required => 0,
@@ -78,7 +87,7 @@ do {
namespace => 'http://ns.opensocial.org/2008/opensocial',
field => 'replies',
is => 'rw',
- isa => 'Str',
+ isa => 'ArrayRef[Str]',
required => 0,
},
+{
@@ -91,15 +100,17 @@ do {
+{
namespace => 'http://ns.opensocial.org/2008/opensocial',
field => 'app_url',
+ typemap => 'appUrl',
is => 'rw',
isa => 'Str',
required => 0,
},
+{
namespace => 'http://ns.opensocial.org/2008/opensocial',
field => 'collection_ids',
+ typemap => 'collectionIds',
is => 'rw',
- isa => 'Str',
+ isa => 'ArrayRef[Str]',
required => 0,
},
+{
@@ -115,11 +126,18 @@ do {
field => 'urls',
metaclass => 'Collection::List',
is => 'rw',
- isa => 'ArrayRef[OpenSocial.Url]',
+ isa => 'OpenSocial.Url.Collection',
required => 0,
provides => +{ count => 'count_urls', },
coerce => 1,
},
+ +{ ### specs is wrong
+ namespace => 'http://ns.opensocial.org/2008/opensocial',
+ field => 'type',
+ is => 'rw',
+ isa => 'OpenSocial.MessageType',
+ required => 0,
+ }
);
my %attrs = __PACKAGE__->setup(@element_fields);
@@ -1,37 +0,0 @@
-package Data::OpenSocial::MessageType;
-
-use Any::Moose;
-use Data::OpenSocial::Types qw(OpenSocial.MessageTypeType);
-
-extends 'Data::OpenSocial::Base';
-
-do {
- my @element_fields = (
- +{
- namespace => 'http://ns.opensocial.org/2008/opensocial',
- field => 'display_value',
- is => 'rw',
- isa => 'Str',
- required => 0,
- predicate => 'has_display_value',
- },
- +{
- namespace => 'http://ns.opensocial.org/2008/opensocial',
- field => 'value',
- is => 'rw',
- isa => 'MessageTypeType',
- required => 0,
- predicate => 'has_value',
- }
- );
-
- my %attrs = __PACKAGE__->setup(@element_fields);
- while ( my ( $field, $attr ) = each %attrs ) {
- has $field => %$attr;
- }
-};
-
-no Any::Moose;
-
-__PACKAGE__->meta->make_immutable;
-
Oops, something went wrong.

0 comments on commit 4118f4c

Please sign in to comment.